Java Code Examples for android.content.res.CompatibilityInfo#alwaysSupportsScreen()

The following examples show how to use android.content.res.CompatibilityInfo#alwaysSupportsScreen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompatModePackages.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void handlePackageAddedLocked(String packageName, boolean updated) {
    ApplicationInfo ai = null;
    try {
        ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
    } catch (RemoteException e) {
    }
    if (ai == null) {
        return;
    }
    CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
    final boolean mayCompat = !ci.alwaysSupportsScreen()
            && !ci.neverSupportsScreen();

    if (updated) {
        // Update -- if the app no longer can run in compat mode, clear
        // any current settings for it.
        if (!mayCompat && mPackages.containsKey(packageName)) {
            mPackages.remove(packageName);
            scheduleWrite();
        }
    }
}
 
Example 2
Source File: CompatModePackages.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public int computeCompatModeLocked(ApplicationInfo ai) {
    final boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
    final Configuration globalConfig = mService.getGlobalConfiguration();
    final CompatibilityInfo info = new CompatibilityInfo(ai, globalConfig.screenLayout,
            globalConfig.smallestScreenWidthDp, enabled);
    if (info.alwaysSupportsScreen()) {
        return ActivityManager.COMPAT_MODE_NEVER;
    }
    if (info.neverSupportsScreen()) {
        return ActivityManager.COMPAT_MODE_ALWAYS;
    }
    return enabled ? ActivityManager.COMPAT_MODE_ENABLED
            : ActivityManager.COMPAT_MODE_DISABLED;
}
 
Example 3
Source File: CompatModePackages.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void setPackageScreenCompatModeLocked(ApplicationInfo ai, int mode) {
    final String packageName = ai.packageName;

    int curFlags = getPackageFlags(packageName);

    boolean enable;
    switch (mode) {
        case ActivityManager.COMPAT_MODE_DISABLED:
            enable = false;
            break;
        case ActivityManager.COMPAT_MODE_ENABLED:
            enable = true;
            break;
        case ActivityManager.COMPAT_MODE_TOGGLE:
            enable = (curFlags&COMPAT_FLAG_ENABLED) == 0;
            break;
        default:
            Slog.w(TAG, "Unknown screen compat mode req #" + mode + "; ignoring");
            return;
    }

    int newFlags = curFlags;
    if (enable) {
        newFlags |= COMPAT_FLAG_ENABLED;
    } else {
        newFlags &= ~COMPAT_FLAG_ENABLED;
    }

    CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
    if (ci.alwaysSupportsScreen()) {
        Slog.w(TAG, "Ignoring compat mode change of " + packageName
                + "; compatibility never needed");
        newFlags = 0;
    }
    if (ci.neverSupportsScreen()) {
        Slog.w(TAG, "Ignoring compat mode change of " + packageName
                + "; compatibility always needed");
        newFlags = 0;
    }

    if (newFlags != curFlags) {
        if (newFlags != 0) {
            mPackages.put(packageName, newFlags);
        } else {
            mPackages.remove(packageName);
        }

        // Need to get compatibility info in new state.
        ci = compatibilityInfoForPackageLocked(ai);

        scheduleWrite();

        final ActivityStack stack = mService.getFocusedStack();
        ActivityRecord starting = stack.restartPackage(packageName);

        // Tell all processes that loaded this package about the change.
        for (int i=mService.mLruProcesses.size()-1; i>=0; i--) {
            ProcessRecord app = mService.mLruProcesses.get(i);
            if (!app.pkgList.containsKey(packageName)) {
                continue;
            }
            try {
                if (app.thread != null) {
                    if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Sending to proc "
                            + app.processName + " new compat " + ci);
                    app.thread.updatePackageCompatibilityInfo(packageName, ci);
                }
            } catch (Exception e) {
            }
        }

        if (starting != null) {
            starting.ensureActivityConfiguration(0 /* globalChanges */,
                    false /* preserveWindow */);
            // And we need to make sure at this point that all other activities
            // are made visible with the correct configuration.
            stack.ensureActivitiesVisibleLocked(starting, 0, !PRESERVE_WINDOWS);
        }
    }
}
 
Example 4
Source File: CompatModePackages.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }

    FileOutputStream fos = null;

    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");

        final IPackageManager pm = AppGlobals.getPackageManager();
        final Configuration globalConfig = mService.getGlobalConfiguration();
        final int screenLayout = globalConfig.screenLayout;
        final int smallestScreenWidthDp = globalConfig.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout,
                    smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }

        out.endTag(null, "compat-packages");
        out.endDocument();

        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}