android:protectionLevel="signature"
/>
<permission
- android:name="com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS"
- android:protectionLevel="signature"
- />
- <permission
android:name="com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS" />
- <uses-permission android:name="com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS" />
<uses-permission android:name="com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST" />
<application
<!-- Permission to receive the com.android.launcher3.action.LAUNCH intent -->
<string name="receive_launch_broadcasts_permission" translatable="false">com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS</string>
- <!-- Permission to receive the com.android.launcher3.SCREEN_ORIENTATION_PREF_CHANGED intent -->
- <string name="receive_update_orientation_broadcasts_permission" translatable="false">com.android.launcher3.permission.RECEIVE_UPDATE_ORIENTATION_BROADCASTS</string>
-
<!-- Permission to receive the com.android.launcher3.action.FIRST_LOAD_COMPLETE intent -->
<string name="receive_first_load_broadcast_permission" translatable="false">com.android.launcher3.permission.RECEIVE_FIRST_LOAD_BROADCAST</string>
}
private Stats mStats;
-
FocusIndicatorView mFocusHandler;
-
- @Thunk boolean mRotationEnabled = false;
- private boolean mScreenOrientationSettingReceiverRegistered = false;
-
- final private BroadcastReceiver mScreenOrientationSettingReceiver =
- new BroadcastReceiver() {
- @Thunk Runnable mUpdateOrientationRunnable = new Runnable() {
- public void run() {
- setOrientation();
- }
- };
-
- @Override
- public void onReceive(Context context, Intent intent) {
- mRotationEnabled = intent.getBooleanExtra(
- Utilities.SCREEN_ROTATION_SETTING_EXTRA, false);
- if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
- setOrientation();
- }
- }
- };
+ private boolean mRotationEnabled = false;
@Thunk void setOrientation() {
if (mRotationEnabled) {
}
}
+ private Runnable mUpdateOrientationRunnable = new Runnable() {
+ public void run() {
+ setOrientation();
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
if (DEBUG_STRICT_MODE) {
// In case we are on a device with locked rotation, we should look at preferences to check
// if the user has specifically allowed rotation.
if (!mRotationEnabled) {
- String updateOrientationBroadcastPermission = getResources().getString(
- R.string.receive_update_orientation_broadcasts_permission);
- registerReceiver(mScreenOrientationSettingReceiver,
- new IntentFilter(Utilities.SCREEN_ROTATION_SETTING_INTENT),
- updateOrientationBroadcastPermission, null);
- mScreenOrientationSettingReceiverRegistered = true;
mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
}
}
}
+ @Override
+ public void onSettingsChanged(String settings, boolean value) {
+ if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) {
+ mRotationEnabled = value;
+ if (!waitUntilResume(mUpdateOrientationRunnable, true)) {
+ mUpdateOrientationRunnable.run();
+ }
+ }
+ }
+
private LauncherCallbacks mLauncherCallbacks;
public void onPostCreate(Bundle savedInstanceState) {
public void onDestroy() {
super.onDestroy();
- if (mScreenOrientationSettingReceiverRegistered) {
- unregisterReceiver(mScreenOrientationSettingReceiver);
- mScreenOrientationSettingReceiverRegistered = false;
- }
-
// Remove all pending runnables
mHandler.removeMessages(ADVANCE_MSG);
mHandler.removeMessages(0);
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.res.Resources;
import android.util.Log;
-import android.view.ViewConfiguration;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
private static LauncherAppState INSTANCE;
private InvariantDeviceProfile mInvariantDeviceProfile;
+
private LauncherAccessibilityDelegate mAccessibilityDelegate;
public static LauncherAppState getInstance() {
public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
public static final String APP_ICONS_DB = "app_icons.db";
- public static final String ROTATION_PREF_FILE = "com.android.launcher3.rotation.prefs";
-
public static final List<String> ALL_FILES = Collections.unmodifiableList(Arrays.asList(
DEFAULT_WALLPAPER_THUMBNAIL,
DEFAULT_WALLPAPER_THUMBNAIL_OLD,
WALLPAPER_IMAGES_DB,
WIDGET_PREVIEWS_DB,
MANAGED_USER_PREFERENCES_KEY,
- APP_ICONS_DB,
- ROTATION_PREF_FILE));
+ APP_ICONS_DB));
// TODO: Delete these files on upgrade
public static final List<String> OBSOLETE_FILES = Collections.unmodifiableList(Arrays.asList(
import android.database.sqlite.SQLiteQueryBuilder;
import android.database.sqlite.SQLiteStatement;
import android.net.Uri;
+import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
+import android.os.Process;
import android.os.StrictMode;
import android.os.UserManager;
import android.text.TextUtils;
return count;
}
+ @Override
+ public Bundle call(String method, String arg, Bundle extras) {
+ if (Binder.getCallingUid() != Process.myUid()) {
+ return null;
+ }
+
+ switch (method) {
+ case LauncherSettings.Settings.METHOD_GET_BOOLEAN: {
+ Bundle result = new Bundle();
+ result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
+ getContext().getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
+ .getBoolean(arg, extras.getBoolean(
+ LauncherSettings.Settings.EXTRA_DEFAULT_VALUE)));
+ return result;
+ }
+ case LauncherSettings.Settings.METHOD_SET_BOOLEAN: {
+ boolean value = extras.getBoolean(LauncherSettings.Settings.EXTRA_VALUE);
+ getContext().getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE)
+ .edit().putBoolean(arg, value).apply();
+ if (mListener != null) {
+ mListener.onSettingsChanged(arg, value);
+ }
+ Bundle result = new Bundle();
+ result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, value);
+ return result;
+ }
+ }
+ return null;
+ }
+
private void notifyListeners() {
// always notify the backup agent
LauncherBackupAgentHelper.dataChanged(getContext());
public interface LauncherProviderChangeListener {
public void onLauncherProviderChange();
+
+ public void onSettingsChanged(String settings, boolean value);
}
*/
static final String OPTIONS = "options";
}
+
+ /**
+ * Launcher settings
+ */
+ public static final class Settings {
+
+ public static final Uri CONTENT_URI = Uri.parse("content://" +
+ ProviderConfig.AUTHORITY + "/settings");
+
+ public static final String METHOD_GET_BOOLEAN = "get_boolean_setting";
+ public static final String METHOD_SET_BOOLEAN = "set_boolean_setting";
+
+ public static final String EXTRA_VALUE = "value";
+ public static final String EXTRA_DEFAULT_VALUE = "default_value";
+ }
}
package com.android.launcher3;
import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
-import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
/**
* This fragment shows the launcher preferences.
*/
- @SuppressWarnings("WeakerAccess")
- public static class LauncherSettingsFragment extends PreferenceFragment {
+ public static class LauncherSettingsFragment extends PreferenceFragment
+ implements OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
- getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE);
addPreferencesFromResource(R.xml.launcher_preferences);
+
+ SwitchPreference pref = (SwitchPreference) findPreference(
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
+ pref.setPersistent(false);
+
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
+ Bundle value = getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_GET_BOOLEAN,
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
+ pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));
+
+ pref.setOnPreferenceChangeListener(this);
}
@Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
- Preference preference) {
- boolean allowRotation = getPreferenceManager().getSharedPreferences().getBoolean(
- Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
- Intent rotationSetting = new Intent(Utilities.SCREEN_ROTATION_SETTING_INTENT);
- String launchBroadcastPermission = getResources().getString(
- R.string.receive_update_orientation_broadcasts_permission);
- rotationSetting.putExtra(Utilities.SCREEN_ROTATION_SETTING_EXTRA, allowRotation);
- getActivity().sendBroadcast(rotationSetting, launchBroadcastPermission);
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, (Boolean) newValue);
+ getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_SET_BOOLEAN,
+ preference.getKey(), extras);
return true;
}
}
private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
- public static final String SCREEN_ROTATION_SETTING_INTENT =
- "come.android.launcher3.SCREEN_ORIENTATION_PREF_CHANGED";
- public static final String SCREEN_ROTATION_SETTING_EXTRA = "screenRotationPref";
public static boolean isPropertyEnabled(String propertyName) {
return Log.isLoggable(propertyName, Log.VERBOSE);
}
public static boolean isAllowRotationPrefEnabled(Context context) {
- SharedPreferences sharedPrefs = context.getSharedPreferences(LauncherFiles.ROTATION_PREF_FILE,
- Context.MODE_MULTI_PROCESS);
+ SharedPreferences sharedPrefs = context.getSharedPreferences(
+ LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
boolean allowRotationPref = sharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
return sForceEnableRotation || allowRotationPref;
}