Search in sources :

Example 6 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project android_frameworks_base by ResurrectionRemix.

the class CompatModePackages method saveCompatModes.

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 int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.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);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 7 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project android_frameworks_base by ResurrectionRemix.

the class CompatModePackages method setPackageScreenCompatModeLocked.

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) {
            stack.ensureActivityConfigurationLocked(starting, 0, false);
            // 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);
        }
    }
}
Also used : CompatibilityInfo(android.content.res.CompatibilityInfo) RemoteException(android.os.RemoteException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 8 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project android_frameworks_base by ResurrectionRemix.

the class DpiTestActivity method init.

public void init(boolean noCompat) {
    try {
        // This is all a dirty hack.  Don't think a real application should
        // be doing it.
        Application app = ActivityThread.currentActivityThread().getApplication();
        ApplicationInfo ai = app.getPackageManager().getApplicationInfo("com.google.android.test.dpi", 0);
        if (noCompat) {
            ai.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
            app.getResources().setCompatibilityInfo(new CompatibilityInfo(ai, getResources().getConfiguration().screenLayout, getResources().getConfiguration().smallestScreenWidthDp, false));
        }
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("ouch", e);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) Application(android.app.Application)

Example 9 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project android_frameworks_base by ResurrectionRemix.

the class ActivityRecord method showStartingWindow.

void showStartingWindow(ActivityRecord prev, boolean createIfNeeded) {
    final CompatibilityInfo compatInfo = service.compatibilityInfoForPackageLocked(info.applicationInfo);
    final boolean shown = service.mWindowManager.setAppStartingWindow(appToken, packageName, theme, compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, prev != null ? prev.appToken : null, createIfNeeded);
    if (shown) {
        mStartingWindowState = STARTING_WINDOW_SHOWN;
    }
}
Also used : CompatibilityInfo(android.content.res.CompatibilityInfo)

Example 10 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project android_frameworks_base by ResurrectionRemix.

the class ViewRootImpl method updateConfiguration.

void updateConfiguration(Configuration config, boolean force) {
    if (DEBUG_CONFIGURATION)
        Log.v(mTag, "Applying new config to window " + mWindowAttributes.getTitle() + ": " + config);
    CompatibilityInfo ci = mDisplay.getDisplayAdjustments().getCompatibilityInfo();
    if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
        config = new Configuration(config);
        ci.applyToConfiguration(mNoncompatDensity, config);
    }
    synchronized (sConfigCallbacks) {
        for (int i = sConfigCallbacks.size() - 1; i >= 0; i--) {
            sConfigCallbacks.get(i).onConfigurationChanged(config);
        }
    }
    if (mView != null) {
        // At this point the resources have been updated to
        // have the most recent config, whatever that is.  Use
        // the one in them which may be newer.
        final Resources localResources = mView.getResources();
        config = localResources.getConfiguration();
        if (force || mLastConfiguration.diff(config) != 0) {
            // Update the display with new DisplayAdjustments.
            mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(mDisplay.getDisplayId(), localResources.getDisplayAdjustments());
            final int lastLayoutDirection = mLastConfiguration.getLayoutDirection();
            final int currentLayoutDirection = config.getLayoutDirection();
            mLastConfiguration.setTo(config);
            if (lastLayoutDirection != currentLayoutDirection && mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) {
                mView.setLayoutDirection(currentLayoutDirection);
            }
            mView.dispatchConfigurationChanged(config);
        }
    }
}
Also used : Configuration(android.content.res.Configuration) CompatibilityInfo(android.content.res.CompatibilityInfo) Resources(android.content.res.Resources) Point(android.graphics.Point)

Aggregations

CompatibilityInfo (android.content.res.CompatibilityInfo)62 RemoteException (android.os.RemoteException)35 Point (android.graphics.Point)24 ApplicationInfo (android.content.pm.ApplicationInfo)17 Configuration (android.content.res.Configuration)13 Resources (android.content.res.Resources)13 RootViewSurfaceTaker (com.android.internal.view.RootViewSurfaceTaker)13 Paint (android.graphics.Paint)9 Rect (android.graphics.Rect)8 Region (android.graphics.Region)8 AndroidRuntimeException (android.util.AndroidRuntimeException)8 IAccessibilityInteractionConnectionCallback (android.view.accessibility.IAccessibilityInteractionConnectionCallback)8 InputMethodManager (android.view.inputmethod.InputMethodManager)8 BaseSurfaceHolder (com.android.internal.view.BaseSurfaceHolder)8 IPackageManager (android.content.pm.IPackageManager)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6