Android R: updateConfiguration()的relaunch App流程

updateConfiguration()的relaunch App流程

在这里插入代码片
切换系统语言更新Configuration
frameworks/base/core/java/com/android/internal/app/LocalePicker.java
public static void updateLocales(LocaleList locales) {
    try {
        IActivityManager am = ActivityManager.getService();
        Configuration config = am.getConfiguration();
        config.setLocales(locales);
        config.userSetLocale = true;
        am.updatePersistentConfiguration(config);
        BackupManager.dataChanged("com.android.providers.settings");
    } catch (RemoteException var3) {
    }

} 
->
IActivityTaskManager.aidl
389      /**
390       * Updates global configuration and applies changes to the entire system.
391       * @param values Update values for global configuration. If null is passed it will request the
392       *               Window Manager to compute new config for the default display.
393       * @throws RemoteException
394       * @return Returns true if the configuration was updated.
395       */
396      boolean updateConfiguration(in Configuration values);
->
ActivityTaskManagerService.java
4833      @Override
4834      public boolean updateConfiguration(Configuration values) {
4835          mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()");
4836  
4837          synchronized (mGlobalLock) {
4838              if (mWindowManager == null) {
4839                  Slog.w(TAG, "Skip updateConfiguration because mWindowManager isn't set");
4840                  return false;
4841              }
4842  
4843              if (values == null) {
4844                  // sentinel: fetch the current configuration from the window manager
4845                  values = mWindowManager.computeNewConfiguration(DEFAULT_DISPLAY);
4846              }
4847  
4848              mH.sendMessage(PooledLambda.obtainMessage(
4849                      ActivityManagerInternal::updateOomLevelsForDisplay, mAmInternal,
4850                      DEFAULT_DISPLAY));
4851  
4852              final long origId = Binder.clearCallingIdentity();
4853              try {
4854                  if (values != null) {
4855                      Settings.System.clearConfiguration(values);
4856                  }
4857                  updateConfigurationLocked(values, null, false, false /* persistent */,
4858                          UserHandle.USER_NULL, false /* deferResume */,
4859                          mTmpUpdateConfigurationResult);
4860                  return mTmpUpdateConfigurationResult.changes != 0;
4861              } finally {
4862                  Binder.restoreCallingIdentity(origId);
4863              }
4864          }
4865      }

->
5630      /**
5631       * Do either or both things: (1) change the current configuration, and (2)
5632       * make sure the given activity is running with the (now) current
5633       * configuration.  Returns true if the activity has been left running, or
5634       * false if <var>starting</var> is being destroyed to match the new
5635       * configuration.
5636       *
5637       * @param userId is only used when persistent parameter is set to true to persist configuration
5638       *               for that particular user
5639       */
5640      boolean updateConfigurationLocked(Configuration values, ActivityRecord starting,
5641              boolean initLocale, boolean persistent, int userId, boolean deferResume,
5642              ActivityTaskManagerService.UpdateConfigurationResult result) {
5643          int changes = 0;
5644          boolean kept = true;
5645  
5646          deferWindowLayout();
5647          try {
5648              if (values != null) {
                      // 分析1
5649                  changes = updateGlobalConfigurationLocked(values, initLocale, persistent, userId,
5650                          deferResume);
5651              }
5652              // 分析2
5653              kept = ensureConfigAndVisibilityAfterUpdate(starting, changes);
5654          } finally {
5655              continueWindowLayout();
5656          }
5657  
5658          if (result != null) {
5659              result.changes = changes;
5660              result.activityRelaunched = !kept;
5661          }
5662          return kept;
5663      }
->
// 分析2
6327      /** Applies latest configuration and/or visibility updates if needed. */
6328      boolean ensureConfigAndVisibilityAfterUpdate(ActivityRecord starting, int changes) {
6329          boolean kept = true;
6330          final ActivityStack mainStack = mRootWindowContainer.getTopDisplayFocusedStack();
6331          // mainStack is null during startup.
6332          if (mainStack != null) {
6333              if (changes != 0 && starting == null) {
6334                  // If the configuration changed, and the caller is not already
6335                  // in the process of starting an activity, then find the top
6336                  // activity to check if its configuration needs to change.
6337                  starting = mainStack.topRunningActivity();
6338              }
6339  
6340              if (starting != null) {
6341                  kept = starting.ensureActivityConfiguration(changes,
6342                          false /* preserveWindow */);
6343                  // And we need to make sure at this point that all other activities
6344                  // are made visible with the correct configuration.
6345                  mRootWindowContainer.ensureActivitiesVisible(starting, changes,
6346                          !PRESERVE_WINDOWS);
6347              }
6348          }
6349  
6350          return kept;
6351      }
->
ActivityRecord.java
ensureActivityConfiguration() {
    if (shouldRelaunchLocked() {
        relaunchActivityLocked(preserveWindow);
    }
}

主要在:shouldRelaunchLocked做一些判断

你可能感兴趣的:(Android,Framework,Android)