Search in sources :

Example 41 with Configuration

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

the class ActivityStack method relaunchActivityLocked.

private void relaunchActivityLocked(ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) {
    if (mService.mSuppressResizeConfigChanges && preserveWindow) {
        r.configChangeFlags = 0;
        return;
    }
    List<ResultInfo> results = null;
    List<ReferrerIntent> newIntents = null;
    if (andResume) {
        results = r.results;
        newIntents = r.newIntents;
    }
    if (DEBUG_SWITCH)
        Slog.v(TAG_SWITCH, "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents + " andResume=" + andResume + " preserveWindow=" + preserveWindow);
    EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), r.task.taskId, r.shortComponentName);
    r.startFreezingScreenLocked(r.app, 0);
    mStackSupervisor.removeChildActivityContainers(r);
    try {
        if (DEBUG_SWITCH || DEBUG_STATES)
            Slog.i(TAG_SWITCH, "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r + " callers=" + Debug.getCallers(6));
        r.forceNewConfig = false;
        mStackSupervisor.activityRelaunchingLocked(r);
        r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, !andResume, new Configuration(mService.mConfiguration), new Configuration(r.task.mOverrideConfig), preserveWindow);
    // Note: don't need to call pauseIfSleepingLocked() here, because
    // the caller will only pass in 'andResume' if this activity is
    // currently resumed, which implies we aren't sleeping.
    } catch (RemoteException e) {
        if (DEBUG_SWITCH || DEBUG_STATES)
            Slog.i(TAG_SWITCH, "Relaunch failed", e);
    }
    if (andResume) {
        if (DEBUG_STATES) {
            Slog.d(TAG_STATES, "Resumed after relaunch " + r);
        }
        r.state = ActivityState.RESUMED;
        // code in resumeTopActivityInnerLocked to complete the resume might be skipped.
        if (!r.visible || r.stopped) {
            mWindowManager.setAppVisibility(r.appToken, true);
            completeResumeLocked(r);
        } else {
            r.results = null;
            r.newIntents = null;
        }
        mService.showUnsupportedZoomDialogIfNeededLocked(r);
        mService.showAskCompatModeDialogLocked(r);
    } else {
        mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
        r.state = ActivityState.PAUSED;
    }
    r.configChangeFlags = 0;
    r.deferRelaunchUntilPaused = false;
    r.preserveWindowOnDeferredRelaunch = false;
}
Also used : ReferrerIntent(com.android.internal.content.ReferrerIntent) Configuration(android.content.res.Configuration) ResultInfo(android.app.ResultInfo) RemoteException(android.os.RemoteException)

Example 42 with Configuration

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

the class ActivityStack method ensureActivityConfigurationLocked.

/**
     * Make sure the given activity matches the current configuration. Returns false if the activity
     * had to be destroyed.  Returns true if the configuration is the same, or the activity will
     * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
     * correct configuration and all other bookkeeping is handled.
     */
boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, boolean preserveWindow) {
    if (mConfigWillChange) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Skipping config check (will change): " + r);
        return true;
    }
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
        Slog.v(TAG_CONFIGURATION, "Ensuring correct configuration: " + r);
    // Short circuit: if the two configurations are equal (the common case), then there is
    // nothing to do.
    final Configuration newConfig = mService.mConfiguration;
    r.task.sanitizeOverrideConfiguration(newConfig);
    final Configuration taskConfig = r.task.mOverrideConfig;
    if (r.configuration.equals(newConfig) && r.taskConfigOverride.equals(taskConfig) && !r.forceNewConfig) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Configuration unchanged in " + r);
        return true;
    }
    // We don't worry about activities that are finishing.
    if (r.finishing) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Configuration doesn't matter in finishing " + r);
        r.stopFreezingScreenLocked(false);
        return true;
    }
    // Okay we now are going to make this activity have the new config.
    // But then we need to figure out how it needs to deal with that.
    final Configuration oldConfig = r.configuration;
    final Configuration oldTaskOverride = r.taskConfigOverride;
    r.configuration = newConfig;
    r.taskConfigOverride = taskConfig;
    int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride);
    final int changes = oldConfig.diff(newConfig) | taskChanges;
    if (changes == 0 && !r.forceNewConfig) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Configuration no differences in " + r);
        // There are no significant differences, so we won't relaunch but should still deliver
        // the new configuration to the client process.
        r.scheduleConfigurationChanged(taskConfig, true);
        return true;
    }
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
        Slog.v(TAG_CONFIGURATION, "Configuration changes for " + r + " ; taskChanges=" + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" + Configuration.configurationDiffToString(changes));
    // configuration and it will pick that up next time it starts.
    if (r.app == null || r.app.thread == null) {
        if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
            Slog.v(TAG_CONFIGURATION, "Configuration doesn't matter not running " + r);
        r.stopFreezingScreenLocked(false);
        r.forceNewConfig = false;
        return true;
    }
    // Figure out how to handle the changes between the configurations.
    if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
        Slog.v(TAG_CONFIGURATION, "Checking to restart " + r.info.name + ": changed=0x" + Integer.toHexString(changes) + ", handles=0x" + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig + ", taskConfig=" + taskConfig);
    if ((changes & (~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
        // Aha, the activity isn't handling the change, so DIE DIE DIE.
        r.configChangeFlags |= changes;
        r.startFreezingScreenLocked(r.app, globalChanges);
        r.forceNewConfig = false;
        preserveWindow &= isResizeOnlyChange(changes);
        if (r.app == null || r.app.thread == null) {
            if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
                Slog.v(TAG_CONFIGURATION, "Config is destroying non-running " + r);
            destroyActivityLocked(r, true, "config");
        } else if (r.state == ActivityState.PAUSING) {
            // do anything now, but just flag that it needs to be restarted when done pausing.
            if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
                Slog.v(TAG_CONFIGURATION, "Config is skipping already pausing " + r);
            r.deferRelaunchUntilPaused = true;
            r.preserveWindowOnDeferredRelaunch = preserveWindow;
            return true;
        } else if (r.state == ActivityState.RESUMED) {
            // "restart!".
            if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
                Slog.v(TAG_CONFIGURATION, "Config is relaunching resumed " + r);
            if (DEBUG_STATES && !r.visible) {
                Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r + " called by " + Debug.getCallers(4));
            }
            relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow);
        } else {
            if (DEBUG_SWITCH || DEBUG_CONFIGURATION)
                Slog.v(TAG_CONFIGURATION, "Config is relaunching non-resumed " + r);
            relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow);
        }
        // All done...  tell the caller we weren't able to keep this activity around.
        return false;
    }
    // Default case: the activity can handle this new configuration, so hand it over.
    // NOTE: We only forward the task override configuration as the system level configuration
    // changes is always sent to all processes when they happen so it can just use whatever
    // system level configuration it last got.
    r.scheduleConfigurationChanged(taskConfig, true);
    r.stopFreezingScreenLocked(false);
    return true;
}
Also used : Configuration(android.content.res.Configuration) Point(android.graphics.Point)

Example 43 with Configuration

use of android.content.res.Configuration 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)

Example 44 with Configuration

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

the class BaseStatusBar method start.

public void start() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDisplay = mWindowManager.getDefaultDisplay();
    mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    mNotificationData = new NotificationData(this);
    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    mDreamManager = IDreamManager.Stub.asInterface(ServiceManager.checkService(DreamService.DREAM_SERVICE));
    mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mSettingsObserver);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false, mSettingsObserver);
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false, mSettingsObserver, UserHandle.USER_ALL);
    if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) {
        mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT), false, mSettingsObserver, UserHandle.USER_ALL);
    }
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS), true, mLockscreenSettingsObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.ALWAYS_HEADSUP_DIALER), false, mSettingsObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.NAVIGATION_BAR_VISIBLE), false, mSettingsObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.HARDWARE_KEYS_DISABLE), false, mSettingsObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.NO_NAVIGATION_NOTIFICATION), false, mSettingsObserver, UserHandle.USER_ALL);
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    final Configuration currentConfig = mContext.getResources().getConfiguration();
    mLocale = currentConfig.locale;
    mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
    mFontScale = currentConfig.fontScale;
    mDensity = currentConfig.densityDpi;
    mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    mLockPatternUtils = new LockPatternUtils(mContext);
    // Connect in to the status bar manager service
    mCommandQueue = new CommandQueue(this);
    int[] switches = new int[9];
    ArrayList<IBinder> binders = new ArrayList<IBinder>();
    ArrayList<String> iconSlots = new ArrayList<>();
    ArrayList<StatusBarIcon> icons = new ArrayList<>();
    Rect fullscreenStackBounds = new Rect();
    Rect dockedStackBounds = new Rect();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconSlots, icons, switches, binders, fullscreenStackBounds, dockedStackBounds);
    } catch (RemoteException ex) {
    // If the system process isn't there we're doomed anyway.
    }
    createAndAddWindows();
    // set up
    mSettingsObserver.onChange(false);
    disable(switches[0], switches[6], false);
    setSystemUiVisibility(switches[1], switches[7], switches[8], 0xffffffff, fullscreenStackBounds, dockedStackBounds);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4], switches[5] != 0);
    // Set up the initial icon state
    int N = iconSlots.size();
    int viewIndex = 0;
    for (int i = 0; i < N; i++) {
        setIcon(iconSlots.get(i), icons.get(i));
    }
    // Set up the initial notification state.
    try {
        mNotificationListener.registerAsSystemService(mContext, new ComponentName(mContext.getPackageName(), getClass().getCanonicalName()), UserHandle.USER_ALL);
    } catch (RemoteException e) {
        Log.e(TAG, "Unable to register notification listener", e);
    }
    if (DEBUG) {
        Log.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", icons.size(), switches[0], switches[1], switches[2], switches[3]));
    }
    mCurrentUserId = ActivityManager.getCurrentUser();
    setHeadsUpUser(mCurrentUserId);
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    filter.addAction(Intent.ACTION_USER_ADDED);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    filter.addAction(ACTION_ENABLE_NAVIGATION_KEY);
    mContext.registerReceiver(mBroadcastReceiver, filter);
    IntentFilter internalFilter = new IntentFilter();
    internalFilter.addAction(WORK_CHALLENGE_UNLOCKED_NOTIFICATION_ACTION);
    internalFilter.addAction(BANNER_ACTION_CANCEL);
    internalFilter.addAction(BANNER_ACTION_SETUP);
    mContext.registerReceiver(mBroadcastReceiver, internalFilter, PERMISSION_SELF, null);
    IntentFilter allUsersFilter = new IntentFilter();
    allUsersFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
    mContext.registerReceiverAsUser(mAllUsersReceiver, UserHandle.ALL, allUsersFilter, null, null);
    updateCurrentProfilesCache();
    IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService("vrmanager"));
    try {
        vrManager.registerListener(mVrStateCallbacks);
    } catch (RemoteException e) {
        Slog.e(TAG, "Failed to register VR mode state listener: " + e);
    }
    mNonBlockablePkgs = new ArraySet<String>();
    Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray(com.android.internal.R.array.config_nonBlockableNotificationPackages));
    mPieSettingsObserver.onChange(false);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PA_PIE_STATE), false, mPieSettingsObserver);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PA_PIE_GRAVITY), false, mPieSettingsObserver);
}
Also used : IntentFilter(android.content.IntentFilter) Rect(android.graphics.Rect) Configuration(android.content.res.Configuration) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) ComponentName(android.content.ComponentName) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) RemoteException(android.os.RemoteException) IVrManager(android.service.vr.IVrManager)

Example 45 with Configuration

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

the class TaskRecord method extractOverrideConfig.

/**
     * Using the existing configuration {@param config}, creates a new task override config such
     * that all the fields that are usually set in an override config are set to the ones in
     * {@param config}.
     */
Configuration extractOverrideConfig(Configuration config) {
    final Configuration extracted = new Configuration(Configuration.EMPTY);
    extracted.screenWidthDp = config.screenWidthDp;
    extracted.screenHeightDp = config.screenHeightDp;
    extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
    extracted.orientation = config.orientation;
    extracted.screenLayout = config.screenLayout;
    extracted.fontScale = config.fontScale;
    return extracted;
}
Also used : Configuration(android.content.res.Configuration)

Aggregations

Configuration (android.content.res.Configuration)824 RemoteException (android.os.RemoteException)158 Resources (android.content.res.Resources)152 Locale (java.util.Locale)112 DisplayMetrics (android.util.DisplayMetrics)88 Intent (android.content.Intent)76 IOException (java.io.IOException)69 Context (android.content.Context)64 Point (android.graphics.Point)48 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)40 Rect (android.graphics.Rect)37 ArrayList (java.util.ArrayList)37 Test (org.junit.Test)29 AndroidRuntimeException (android.util.AndroidRuntimeException)28 View (android.view.View)27 ComponentName (android.content.ComponentName)25 Bundle (android.os.Bundle)25 IBinder (android.os.IBinder)24 WindowManager (android.view.WindowManager)24 Nullable (android.annotation.Nullable)22