Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 077ca39f authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Implement flag to not relaunch on dock config change for apps without...

Merge "Implement flag to not relaunch on dock config change for apps without -desk resources" into tm-qpr-dev
parents 21c45b5c 5fdd2f3e
Loading
Loading
Loading
Loading
+36 −2
Original line number Original line Diff line number Diff line
@@ -29,6 +29,8 @@ import static android.app.servertransaction.ActivityLifecycleItem.ON_STOP;
import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE;
import static android.app.servertransaction.ActivityLifecycleItem.PRE_ON_CREATE;
import static android.content.ContentResolver.DEPRECATE_DATA_COLUMNS;
import static android.content.ContentResolver.DEPRECATE_DATA_COLUMNS;
import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX;
import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX;
import static android.content.res.Configuration.UI_MODE_TYPE_DESK;
import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.window.ConfigurationHelper.freeTextLayoutCachesIfNeeded;
import static android.window.ConfigurationHelper.freeTextLayoutCachesIfNeeded;
@@ -194,6 +196,7 @@ import android.window.SplashScreen;
import android.window.SplashScreenView;
import android.window.SplashScreenView;
import android.window.WindowProviderService;
import android.window.WindowProviderService;


import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVoiceInteractor;
@@ -5890,9 +5893,21 @@ public final class ActivityThread extends ClientTransactionHandler
        final boolean shouldUpdateResources = hasPublicResConfigChange
        final boolean shouldUpdateResources = hasPublicResConfigChange
                || shouldUpdateResources(activityToken, currentResConfig, newConfig,
                || shouldUpdateResources(activityToken, currentResConfig, newConfig,
                amOverrideConfig, movedToDifferentDisplay, hasPublicResConfigChange);
                amOverrideConfig, movedToDifferentDisplay, hasPublicResConfigChange);

        // TODO(b/266924897): temporary workaround, remove for U.
        boolean skipActivityRelaunchWhenDocking = activity.getResources().getBoolean(
                R.bool.config_skipActivityRelaunchWhenDocking);
        int handledConfigChanges = activity.mActivityInfo.getRealConfigChanged();
        if (skipActivityRelaunchWhenDocking && onlyDeskInUiModeChanged(activity.mCurrentConfig,
                newConfig)) {
            // If we're not relaunching this activity when docking, we should send the configuration
            // changed event. Pretend as if the activity is handling uiMode config changes in its
            // manifest so that we'll report any dock changes.
            handledConfigChanges |= ActivityInfo.CONFIG_UI_MODE;
        }

        final boolean shouldReportChange = shouldReportChange(activity.mCurrentConfig, newConfig,
        final boolean shouldReportChange = shouldReportChange(activity.mCurrentConfig, newConfig,
                r != null ? r.mSizeConfigurations : null,
                r != null ? r.mSizeConfigurations : null, handledConfigChanges);
                activity.mActivityInfo.getRealConfigChanged());
        // Nothing significant, don't proceed with updating and reporting.
        // Nothing significant, don't proceed with updating and reporting.
        if (!shouldUpdateResources && !shouldReportChange) {
        if (!shouldUpdateResources && !shouldReportChange) {
            return null;
            return null;
@@ -5938,6 +5953,25 @@ public final class ActivityThread extends ClientTransactionHandler
        return configToReport;
        return configToReport;
    }
    }


    /**
     * Returns true if the uiMode configuration changed, and desk mode
     * ({@link android.content.res.Configuration#UI_MODE_TYPE_DESK}) was the only change to uiMode.
     */
    private boolean onlyDeskInUiModeChanged(Configuration oldConfig, Configuration newConfig) {
        boolean deskModeChanged = isInDeskUiMode(oldConfig) != isInDeskUiMode(newConfig);

        // UI mode contains fields other than the UI mode type, so determine if any other fields
        // changed.
        boolean uiModeOtherFieldsChanged =
                (oldConfig.uiMode & ~UI_MODE_TYPE_MASK) != (newConfig.uiMode & ~UI_MODE_TYPE_MASK);

        return deskModeChanged && !uiModeOtherFieldsChanged;
    }

    private static boolean isInDeskUiMode(Configuration config) {
        return (config.uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_DESK;
    }

    /**
    /**
     * Returns {@code true} if {@link Activity#onConfigurationChanged(Configuration)} should be
     * Returns {@code true} if {@link Activity#onConfigurationChanged(Configuration)} should be
     * dispatched.
     * dispatched.
+11 −0
Original line number Original line Diff line number Diff line
@@ -1452,6 +1452,16 @@ public final class AssetManager implements AutoCloseable {
        }
        }
    }
    }


    /**
     * @hide
     */
    Configuration[] getSizeAndUiModeConfigurations() {
        synchronized (this) {
            ensureValidLocked();
            return nativeGetSizeAndUiModeConfigurations(mObject);
        }
    }

    /**
    /**
     * Change the configuration used when retrieving resources.  Not for use by
     * Change the configuration used when retrieving resources.  Not for use by
     * applications.
     * applications.
@@ -1603,6 +1613,7 @@ public final class AssetManager implements AutoCloseable {
    private static native @Nullable String nativeGetResourceEntryName(long ptr, @AnyRes int resid);
    private static native @Nullable String nativeGetResourceEntryName(long ptr, @AnyRes int resid);
    private static native @Nullable String[] nativeGetLocales(long ptr, boolean excludeSystem);
    private static native @Nullable String[] nativeGetLocales(long ptr, boolean excludeSystem);
    private static native @Nullable Configuration[] nativeGetSizeConfigurations(long ptr);
    private static native @Nullable Configuration[] nativeGetSizeConfigurations(long ptr);
    private static native @Nullable Configuration[] nativeGetSizeAndUiModeConfigurations(long ptr);
    private static native void nativeSetResourceResolutionLoggingEnabled(long ptr, boolean enabled);
    private static native void nativeSetResourceResolutionLoggingEnabled(long ptr, boolean enabled);
    private static native @Nullable String nativeGetLastResourceResolution(long ptr);
    private static native @Nullable String nativeGetLastResourceResolution(long ptr);


+5 −0
Original line number Original line Diff line number Diff line
@@ -2207,6 +2207,11 @@ public class Resources {
        return mResourcesImpl.getSizeConfigurations();
        return mResourcesImpl.getSizeConfigurations();
    }
    }


    /** @hide */
    public Configuration[] getSizeAndUiModeConfigurations() {
        return mResourcesImpl.getSizeAndUiModeConfigurations();
    }

    /**
    /**
     * Return the compatibility mode information for the application.
     * Return the compatibility mode information for the application.
     * The returned object should be treated as read-only.
     * The returned object should be treated as read-only.
+4 −0
Original line number Original line Diff line number Diff line
@@ -203,6 +203,10 @@ public class ResourcesImpl {
        return mAssets.getSizeConfigurations();
        return mAssets.getSizeConfigurations();
    }
    }


    Configuration[] getSizeAndUiModeConfigurations() {
        return mAssets.getSizeAndUiModeConfigurations();
    }

    CompatibilityInfo getCompatibilityInfo() {
    CompatibilityInfo getCompatibilityInfo() {
        return mDisplayAdjustments.getCompatibilityInfo();
        return mDisplayAdjustments.getCompatibilityInfo();
    }
    }
+14 −1
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ static struct configuration_offsets_t {
  jfieldID mScreenWidthDpOffset;
  jfieldID mScreenWidthDpOffset;
  jfieldID mScreenHeightDpOffset;
  jfieldID mScreenHeightDpOffset;
  jfieldID mScreenLayoutOffset;
  jfieldID mScreenLayoutOffset;
  jfieldID mUiMode;
} gConfigurationOffsets;
} gConfigurationOffsets;


static struct arraymap_offsets_t {
static struct arraymap_offsets_t {
@@ -1027,10 +1028,11 @@ static jobject ConstructConfigurationObject(JNIEnv* env, const ResTable_config&
  env->SetIntField(result, gConfigurationOffsets.mScreenWidthDpOffset, config.screenWidthDp);
  env->SetIntField(result, gConfigurationOffsets.mScreenWidthDpOffset, config.screenWidthDp);
  env->SetIntField(result, gConfigurationOffsets.mScreenHeightDpOffset, config.screenHeightDp);
  env->SetIntField(result, gConfigurationOffsets.mScreenHeightDpOffset, config.screenHeightDp);
  env->SetIntField(result, gConfigurationOffsets.mScreenLayoutOffset, config.screenLayout);
  env->SetIntField(result, gConfigurationOffsets.mScreenLayoutOffset, config.screenLayout);
  env->SetIntField(result, gConfigurationOffsets.mUiMode, config.uiMode);
  return result;
  return result;
}
}


static jobjectArray NativeGetSizeConfigurations(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
static jobjectArray GetSizeAndUiModeConfigurations(JNIEnv* env, jlong ptr) {
  ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
  ScopedLock<AssetManager2> assetmanager(AssetManagerFromLong(ptr));
  auto configurations = assetmanager->GetResourceConfigurations(true /*exclude_system*/,
  auto configurations = assetmanager->GetResourceConfigurations(true /*exclude_system*/,
                                                                false /*exclude_mipmap*/);
                                                                false /*exclude_mipmap*/);
@@ -1057,6 +1059,14 @@ static jobjectArray NativeGetSizeConfigurations(JNIEnv* env, jclass /*clazz*/, j
  return array;
  return array;
}
}


static jobjectArray NativeGetSizeConfigurations(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
  return GetSizeAndUiModeConfigurations(env, ptr);
}

static jobjectArray NativeGetSizeAndUiModeConfigurations(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
  return GetSizeAndUiModeConfigurations(env, ptr);
}

static jintArray NativeAttributeResolutionStack(
static jintArray NativeAttributeResolutionStack(
    JNIEnv* env, jclass /*clazz*/, jlong ptr,
    JNIEnv* env, jclass /*clazz*/, jlong ptr,
    jlong theme_ptr, jint xml_style_res,
    jlong theme_ptr, jint xml_style_res,
@@ -1487,6 +1497,8 @@ static const JNINativeMethod gAssetManagerMethods[] = {
    {"nativeGetLocales", "(JZ)[Ljava/lang/String;", (void*)NativeGetLocales},
    {"nativeGetLocales", "(JZ)[Ljava/lang/String;", (void*)NativeGetLocales},
    {"nativeGetSizeConfigurations", "(J)[Landroid/content/res/Configuration;",
    {"nativeGetSizeConfigurations", "(J)[Landroid/content/res/Configuration;",
     (void*)NativeGetSizeConfigurations},
     (void*)NativeGetSizeConfigurations},
    {"nativeGetSizeAndUiModeConfigurations", "(J)[Landroid/content/res/Configuration;",
     (void*)NativeGetSizeAndUiModeConfigurations},


    // Style attribute related methods.
    // Style attribute related methods.
    {"nativeAttributeResolutionStack", "(JJIII)[I", (void*)NativeAttributeResolutionStack},
    {"nativeAttributeResolutionStack", "(JJIII)[I", (void*)NativeAttributeResolutionStack},
@@ -1565,6 +1577,7 @@ int register_android_content_AssetManager(JNIEnv* env) {
      GetFieldIDOrDie(env, configurationClass, "screenHeightDp", "I");
      GetFieldIDOrDie(env, configurationClass, "screenHeightDp", "I");
  gConfigurationOffsets.mScreenLayoutOffset =
  gConfigurationOffsets.mScreenLayoutOffset =
          GetFieldIDOrDie(env, configurationClass, "screenLayout", "I");
          GetFieldIDOrDie(env, configurationClass, "screenLayout", "I");
  gConfigurationOffsets.mUiMode = GetFieldIDOrDie(env, configurationClass, "uiMode", "I");


  jclass arrayMapClass = FindClassOrDie(env, "android/util/ArrayMap");
  jclass arrayMapClass = FindClassOrDie(env, "android/util/ArrayMap");
  gArrayMapOffsets.classObject = MakeGlobalRefOrDie(env, arrayMapClass);
  gArrayMapOffsets.classObject = MakeGlobalRefOrDie(env, arrayMapClass);
Loading