Search in sources :

Example 21 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project platform_frameworks_base by android.

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 22 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project platform_frameworks_base by android.

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 23 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project XobotOS by xamarin.

the class Display method getSizeInternal.

private void getSizeInternal(Point outSize, boolean doCompat) {
    try {
        IWindowManager wm = getWindowManager();
        if (wm != null) {
            wm.getDisplaySize(outSize);
            CompatibilityInfo ci;
            if (doCompat && (ci = mCompatibilityInfo.getIfNeeded()) != null) {
                synchronized (mTmpMetrics) {
                    mTmpMetrics.noncompatWidthPixels = outSize.x;
                    mTmpMetrics.noncompatHeightPixels = outSize.y;
                    mTmpMetrics.density = mDensity;
                    ci.applyToDisplayMetrics(mTmpMetrics);
                    outSize.x = mTmpMetrics.widthPixels;
                    outSize.y = mTmpMetrics.heightPixels;
                }
            }
        } else {
            // This is just for boot-strapping, initializing the
            // system process before the window manager is up.
            outSize.x = getRawWidth();
            outSize.y = getRawHeight();
        }
        if (false) {
            RuntimeException here = new RuntimeException("here");
            here.fillInStackTrace();
            Slog.v(TAG, "Returning display size: " + outSize, here);
        }
        if (DEBUG_DISPLAY_SIZE && doCompat)
            Slog.v(TAG, "Returning display size: " + outSize);
    } catch (RemoteException e) {
        Slog.w("Display", "Unable to get display size", e);
    }
}
Also used : CompatibilityInfo(android.content.res.CompatibilityInfo) RemoteException(android.os.RemoteException)

Example 24 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project XobotOS by xamarin.

the class ViewRootImpl method setView.

/**
     * We have one child
     */
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
    synchronized (this) {
        if (mView == null) {
            mView = view;
            mFallbackEventHandler.setView(view);
            mWindowAttributes.copyFrom(attrs);
            attrs = mWindowAttributes;
            if (view instanceof RootViewSurfaceTaker) {
                mSurfaceHolderCallback = ((RootViewSurfaceTaker) view).willYouTakeTheSurface();
                if (mSurfaceHolderCallback != null) {
                    mSurfaceHolder = new TakenSurfaceHolder();
                    mSurfaceHolder.setFormat(PixelFormat.UNKNOWN);
                }
            }
            // If the application owns the surface, don't enable hardware acceleration
            if (mSurfaceHolder == null) {
                enableHardwareAcceleration(attrs);
            }
            CompatibilityInfo compatibilityInfo = mCompatibilityInfo.get();
            mTranslator = compatibilityInfo.getTranslator();
            if (mTranslator != null) {
                mSurface.setCompatibilityTranslator(mTranslator);
            }
            boolean restore = false;
            if (mTranslator != null) {
                restore = true;
                attrs.backup();
                mTranslator.translateWindowLayout(attrs);
            }
            if (DEBUG_LAYOUT)
                Log.d(TAG, "WindowLayout in setView:" + attrs);
            if (!compatibilityInfo.supportsScreen()) {
                attrs.flags |= WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW;
                mLastInCompatMode = true;
            }
            mSoftInputMode = attrs.softInputMode;
            mWindowAttributesChanged = true;
            mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED;
            mAttachInfo.mRootView = view;
            mAttachInfo.mScalingRequired = mTranslator != null;
            mAttachInfo.mApplicationScale = mTranslator == null ? 1.0f : mTranslator.applicationScale;
            if (panelParentView != null) {
                mAttachInfo.mPanelParentWindowToken = panelParentView.getApplicationWindowToken();
            }
            mAdded = true;
            int res;
            /* = WindowManagerImpl.ADD_OKAY; */
            // Schedule the first layout -before- adding to the window
            // manager, to make sure we do the relayout before receiving
            // any other events from the system.
            requestLayout();
            if ((mWindowAttributes.inputFeatures & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
                mInputChannel = new InputChannel();
            }
            try {
                mOrigWindowType = mWindowAttributes.type;
                res = sWindowSession.add(mWindow, mSeq, mWindowAttributes, getHostVisibility(), mAttachInfo.mContentInsets, mInputChannel);
            } catch (RemoteException e) {
                mAdded = false;
                mView = null;
                mAttachInfo.mRootView = null;
                mInputChannel = null;
                mFallbackEventHandler.setView(null);
                unscheduleTraversals();
                throw new RuntimeException("Adding window failed", e);
            } finally {
                if (restore) {
                    attrs.restore();
                }
            }
            if (mTranslator != null) {
                mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets);
            }
            mPendingContentInsets.set(mAttachInfo.mContentInsets);
            mPendingVisibleInsets.set(0, 0, 0, 0);
            if (DEBUG_LAYOUT)
                Log.v(TAG, "Added window " + mWindow);
            if (res < WindowManagerImpl.ADD_OKAY) {
                mView = null;
                mAttachInfo.mRootView = null;
                mAdded = false;
                mFallbackEventHandler.setView(null);
                unscheduleTraversals();
                switch(res) {
                    case WindowManagerImpl.ADD_BAD_APP_TOKEN:
                    case WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window -- token " + attrs.token + " is not valid; is your activity running?");
                    case WindowManagerImpl.ADD_NOT_APP_TOKEN:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window -- token " + attrs.token + " is not for an application");
                    case WindowManagerImpl.ADD_APP_EXITING:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window -- app for token " + attrs.token + " is exiting");
                    case WindowManagerImpl.ADD_DUPLICATE_ADD:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window -- window " + mWindow + " has already been added");
                    case WindowManagerImpl.ADD_STARTING_NOT_NEEDED:
                        // right away, anyway.
                        return;
                    case WindowManagerImpl.ADD_MULTIPLE_SINGLETON:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window " + mWindow + " -- another window of this type already exists");
                    case WindowManagerImpl.ADD_PERMISSION_DENIED:
                        throw new WindowManagerImpl.BadTokenException("Unable to add window " + mWindow + " -- permission denied for this window type");
                }
                throw new RuntimeException("Unable to add window -- unknown error code " + res);
            }
            if (view instanceof RootViewSurfaceTaker) {
                mInputQueueCallback = ((RootViewSurfaceTaker) view).willYouTakeTheInputQueue();
            }
            if (mInputChannel != null) {
                if (mInputQueueCallback != null) {
                    mInputQueue = new InputQueue(mInputChannel);
                    mInputQueueCallback.onInputQueueCreated(mInputQueue);
                } else {
                    InputQueue.registerInputChannel(mInputChannel, mInputHandler, Looper.myQueue());
                }
            }
            view.assignParent(this);
            mAddedTouchMode = (res & WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE) != 0;
            mAppVisible = (res & WindowManagerImpl.ADD_FLAG_APP_VISIBLE) != 0;
            if (mAccessibilityManager.isEnabled()) {
                mAccessibilityInteractionConnectionManager.ensureConnection();
            }
        }
    }
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) RootViewSurfaceTaker(com.android.internal.view.RootViewSurfaceTaker) CompatibilityInfo(android.content.res.CompatibilityInfo) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 25 with CompatibilityInfo

use of android.content.res.CompatibilityInfo in project XobotOS by xamarin.

the class ViewRootImpl method updateConfiguration.

void updateConfiguration(Configuration config, boolean force) {
    if (DEBUG_CONFIGURATION)
        Log.v(TAG, "Applying new config to window " + mWindowAttributes.getTitle() + ": " + config);
    CompatibilityInfo ci = mCompatibilityInfo.getIfNeeded();
    if (ci != null) {
        config = new Configuration(config);
        ci.applyToConfiguration(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 on in them which may be newer.
        config = mView.getResources().getConfiguration();
        if (force || mLastConfiguration.diff(config) != 0) {
            mLastConfiguration.setTo(config);
            mView.dispatchConfigurationChanged(config);
        }
    }
}
Also used : Configuration(android.content.res.Configuration) CompatibilityInfo(android.content.res.CompatibilityInfo) Paint(android.graphics.Paint) 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