のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

CONFIGURATION_CHANGEDを投げるところ

sgrep CONFIGURATION_CHANGED
./frameworks/base/core/java/android/content/Intent.java:1629:
public static final String ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
./frameworks/base/services/java/com/android/server/am/ActivityManagerService.java:13455:
Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED);
/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
   13361     /**
   13362      * Do either or both things: (1) change the current configuration, and (2)
   13363      * make sure the given activity is running with the (now) current
   13364      * configuration.  Returns true if the activity has been left running, or
   13365      * false if <var>starting</var> is being destroyed to match the new
   13366      * configuration.
   13367      * @param persistent TODO
   13368      */
   13369     public boolean updateConfigurationLocked(Configuration values,
   13370             ActivityRecord starting, boolean persistent, boolean initLocale) {
   13371         int changes = 0;
   13372 
   13373         boolean kept = true;
   13374 
   13375         if (values != null) {
   13376             Configuration newConfig = new Configuration(mConfiguration);
   13377             changes = newConfig.updateFrom(values);
   13378             if (changes != 0) {
   13379                 if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
   13380                     Slog.i(TAG, "Updating configuration to: " + values);
   13381                 }
   13382 
   13383                 EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
   13384 
   13385                 if (values.locale != null && !initLocale) {
   13386                     saveLocaleLocked(values.locale,
   13387                                      !values.locale.equals(mConfiguration.locale),
   13388                                      values.userSetLocale);
   13389                 }
   13390 
   13391                 mConfigurationSeq++;
   13392                 if (mConfigurationSeq <= 0) {
   13393                     mConfigurationSeq = 1;
   13394                 }
   13395                 newConfig.seq = mConfigurationSeq;
   13396                 mConfiguration = newConfig;
   13397                 Slog.i(TAG, "Config changed: " + newConfig);
   13398 
   13399                 final Configuration configCopy = new Configuration(mConfiguration);
   13400 
   13401                 AttributeCache ac = AttributeCache.instance();
   13402                 if (ac != null) {
   13403                     ac.updateConfiguration(configCopy);
   13404                 }
   13405 
   13406                 // Make sure all resources in our process are updated
   13407                 // right now, so that anyone who is going to retrieve
   13408                 // resource values after we return will be sure to get
   13409                 // the new ones.  This is especially important during
   13410                 // boot, where the first config change needs to guarantee
   13411                 // all resources have that config before following boot
   13412                 // code is executed.
   13413                 mSystemThread.applyConfigurationToResources(configCopy);
   13414 
   13415                 if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) {
   13416                     Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
   13417                     msg.obj = new Configuration(configCopy);
   13418                     mHandler.sendMessage(msg);
   13419                 }
   13420 
   13421                 for (int i=mLruProcesses.size()-1; i>=0; i--) {
   13422                     ProcessRecord app = mLruProcesses.get(i);
   13423                     try {
   13424                         if (app.thread != null) {
   13425                             if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending to proc "
   13426                                     + app.processName + " new config " + mConfiguration);
   13427                             app.thread.scheduleConfigurationChanged(configCopy);
   13428                         }
   13429                     } catch (Exception e) {
   13430                     }
   13431                 }
   13432                 Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED);
   13433                 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
   13434                         | Intent.FLAG_RECEIVER_REPLACE_PENDING);
   13435                 broadcastIntentLocked(null, null, intent, null, null, 0, null, null,
   13436                         null, false, false, MY_PID, Process.SYSTEM_UID);
   13437                 if ((changes&ActivityInfo.CONFIG_LOCALE) != 0) {
   13438                     broadcastIntentLocked(null, null,
   13439                             new Intent(Intent.ACTION_LOCALE_CHANGED),
   13440                             null, null, 0, null, null,
   13441                             null, false, false, MY_PID, Process.SYSTEM_UID);
   13442                 }
   13443             }
   13444         }
   13445 
   13446         if (changes != 0 && starting == null) {
   13447             // If the configuration changed, and the caller is not already
   13448             // in the process of starting an activity, then find the top
   13449             // activity to check if its configuration needs to change.
   13450             starting = mMainStack.topRunningActivityLocked(null);
   13451         }
   13452 
   13453         if (starting != null) {
   13454             kept = mMainStack.ensureActivityConfigurationLocked(starting, changes);
   13455             // And we need to make sure at this point that all other activities
   13456             // are made visible with the correct configuration.
   13457             mMainStack.ensureActivitiesVisibleLocked(starting, changes);
   13458         }
   13459 
   13460         if (values != null && mWindowManager != null) {
   13461             mWindowManager.setNewConfiguration(mConfiguration);
   13462         }
   13463 
   13464         return kept;
   13465     }
   13466 
/frameworks/base/core/java/android/content/res/Configuration.java
   480     /**
    481      * Copy the fields from delta into this Configuration object, keeping
    482      * track of which ones have changed.  Any undefined fields in
    483      * <var>delta</var> are ignored and not copied in to the current
    484      * Configuration.
    485      * @return Returns a bit mask of the changed fields, as per
    486      * {@link #diff}.
    487      */
    488     public int updateFrom(Configuration delta) {
    489         int changed = 0;
    490         if (delta.fontScale > 0 && fontScale != delta.fontScale) {
    491             changed |= ActivityInfo.CONFIG_FONT_SCALE;
    492             fontScale = delta.fontScale;
    493         }
    494         if (delta.mcc != 0 && mcc != delta.mcc) {
    495             changed |= ActivityInfo.CONFIG_MCC;
    496             mcc = delta.mcc;
    497         }
    498         if (delta.mnc != 0 && mnc != delta.mnc) {
    499             changed |= ActivityInfo.CONFIG_MNC;
    500             mnc = delta.mnc;
    501         }
    502         if (delta.locale != null
    503                 && (locale == null || !locale.equals(delta.locale))) {
    504             changed |= ActivityInfo.CONFIG_LOCALE;
    505             locale = delta.locale != null
    506                     ? (Locale) delta.locale.clone() : null;
    507             textLayoutDirection = LocaleUtil.getLayoutDirectionFromLocale(locale);
    508         }
    509         if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
    510         {
    511             userSetLocale = true;
    512             changed |= ActivityInfo.CONFIG_LOCALE;
    513         }
    514         if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
    515                 && touchscreen != delta.touchscreen) {
    516             changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
    517             touchscreen = delta.touchscreen;
    518         }
    519         if (delta.keyboard != KEYBOARD_UNDEFINED
    520                 && keyboard != delta.keyboard) {
    521             changed |= ActivityInfo.CONFIG_KEYBOARD;
    522             keyboard = delta.keyboard;
    523         }
    524         if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
    525                 && keyboardHidden != delta.keyboardHidden) {
    526             changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
    527             keyboardHidden = delta.keyboardHidden;
    528         }
    529         if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
    530                 && hardKeyboardHidden != delta.hardKeyboardHidden) {
    531             changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
    532             hardKeyboardHidden = delta.hardKeyboardHidden;
    533         }
    534         if (delta.navigation != NAVIGATION_UNDEFINED
    535                 && navigation != delta.navigation) {
    536             changed |= ActivityInfo.CONFIG_NAVIGATION;
    537             navigation = delta.navigation;
    538         }
    539         if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
    540                 && navigationHidden != delta.navigationHidden) {
    541             changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
    542             navigationHidden = delta.navigationHidden;
    543         }
    544         if (delta.orientation != ORIENTATION_UNDEFINED
    545                 && orientation != delta.orientation) {
    546             changed |= ActivityInfo.CONFIG_ORIENTATION;
    547             orientation = delta.orientation;
    548         }
    549         if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
    550                 && screenLayout != delta.screenLayout) {
    551             changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
    552             screenLayout = delta.screenLayout;
    553         }
    554         if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
    555                 && uiMode != delta.uiMode) {
    556             changed |= ActivityInfo.CONFIG_UI_MODE;
    557             if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
    558                 uiMode = (uiMode&~UI_MODE_TYPE_MASK)
    559                         | (delta.uiMode&UI_MODE_TYPE_MASK);
    560             }
    561             if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
    562                 uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
    563                         | (delta.uiMode&UI_MODE_NIGHT_MASK);
    564             }
    565         }
    566         if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
    567                 && screenWidthDp != delta.screenWidthDp) {
    568             changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
    569             screenWidthDp = delta.screenWidthDp;
    570         }
    571         if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
    572                 && screenHeightDp != delta.screenHeightDp) {
    573             changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
    574             screenHeightDp = delta.screenHeightDp;
    575         }
    576         if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
    577             smallestScreenWidthDp = delta.smallestScreenWidthDp;
    578         }
    579         if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
    580             compatScreenWidthDp = delta.compatScreenWidthDp;
    581         }
    582         if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
    583             compatScreenHeightDp = delta.compatScreenHeightDp;
    584         }
    585         if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
    586             compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
    587         }
    588 
    589         if (delta.seq != 0) {
    590             seq = delta.seq;
    591         }
    592 
    593         return changed;
    594     }