diff options
author | Roman Birg <roman@cyngn.com> | 2015-05-15 11:00:59 -0700 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-26 16:11:15 -0700 |
commit | 7c5caefa7ab469ea5eb1acb73e8afc1c2567d81f (patch) | |
tree | 54182224a716ae6bdb945e279e54214d51660a8a /src/com/android/settings/profiles | |
parent | fa8f2cc00dec3cd970508c19320ff8a4f41339c7 (diff) | |
download | packages_apps_Settings-7c5caefa7ab469ea5eb1acb73e8afc1c2567d81f.zip packages_apps_Settings-7c5caefa7ab469ea5eb1acb73e8afc1c2567d81f.tar.gz packages_apps_Settings-7c5caefa7ab469ea5eb1acb73e8afc1c2567d81f.tar.bz2 |
Settings: setup Default Profile after OOBE has run
Change-Id: Ic961d5bfd041830baff4d6d73fc36762a1f6dfcf
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src/com/android/settings/profiles')
-rw-r--r-- | src/com/android/settings/profiles/SetupActionsFragment.java | 202 | ||||
-rw-r--r-- | src/com/android/settings/profiles/SetupDefaultProfileReceiver.java | 27 |
2 files changed, 129 insertions, 100 deletions
diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 199e477..34ce056 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -313,105 +313,10 @@ public class SetupActionsFragment extends SettingsPreferenceFragment } private void fillProfileFromCurrentSettings() { - new AsyncTask<Profile, Void, Void>() { + new AsyncTask<Void, Void, Void>() { @Override - protected Void doInBackground(Profile... params) { - // bt - if (DeviceUtils.deviceSupportsBluetooth()) { - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH, - BluetoothAdapter.getDefaultAdapter().isEnabled() ? 1 : 0, - true)); - } - - // gps - LocationManager locationManager = (LocationManager) - getSystemService(Context.LOCATION_SERVICE); - boolean gpsEnabled = locationManager. - isProviderEnabled(LocationManager.GPS_PROVIDER); - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS, - gpsEnabled ? 1 : 0, true)); - - // wifi - WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFI, - wifiManager.isWifiEnabled() ? 1 : 0, true)); - - // auto sync data - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_SYNC, - ContentResolver.getMasterSyncAutomatically() ? 1 : 0, true)); - - // mobile data - if (DeviceUtils.deviceSupportsMobileData(getActivity())) { - ConnectivityManager cm = (ConnectivityManager) - getSystemService(Context.CONNECTIVITY_SERVICE); - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA, - cm.getMobileDataEnabled() ? 1 : 0, true)); - } - - // wifi hotspot - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFIAP, - wifiManager.isWifiApEnabled() ? 1 : 0, true)); - - // 2g/3g/4g - // skipping this one - - // nfc - if (DeviceUtils.deviceSupportsNfc(getActivity())) { - NfcManager nfcManager = (NfcManager) getSystemService(Context.NFC_SERVICE); - mProfile.setConnectionSettings( - new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_NFC, - nfcManager.getDefaultAdapter().isEnabled() ? 1 : 0, true)); - } - - // alarm volume - final AudioManager am = (AudioManager) getActivity() - .getSystemService(Context.AUDIO_SERVICE); - mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM, - am.getStreamVolume(AudioManager.STREAM_ALARM), true)); - - // media volume - mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC, - am.getStreamVolume(AudioManager.STREAM_MUSIC), true)); - - // ringtone volume - mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING, - am.getStreamVolume(AudioManager.STREAM_RING), true)); - - // notification volume - mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION, - am.getStreamVolume(AudioManager.STREAM_NOTIFICATION), true)); - - // ring mode - String ringValue; - switch (am.getRingerMode()) { - default: - case AudioManager.RINGER_MODE_NORMAL: - ringValue = "normal"; - break; - case AudioManager.RINGER_MODE_SILENT: - ringValue = "mute"; - break; - case AudioManager.RINGER_MODE_VIBRATE: - ringValue = "vibrate"; - break; - } - mProfile.setRingMode(new RingModeSettings(ringValue, true)); - - // airplane mode - boolean airplaneMode = Settings.Global.getInt(getActivity().getContentResolver(), - Settings.Global.AIRPLANE_MODE_ON, 0) != 0; - mProfile.setAirplaneMode(new AirplaneModeSettings(airplaneMode ? 1 : 0, true)); - - // lock screen mode - // populated only from profiles, so we can read the current profile, - // but let's skip this one - + protected Void doInBackground(Void... params) { + fillProfileWithCurrentSettings(getActivity(), mProfile); updateProfile(); return null; } @@ -420,9 +325,106 @@ public class SetupActionsFragment extends SettingsPreferenceFragment protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); rebuildItemList(); - } - }.execute(mProfile); + }.execute((Void) null); + } + + public static void fillProfileWithCurrentSettings(Context context, Profile profile) { + // bt + if (DeviceUtils.deviceSupportsBluetooth()) { + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH, + BluetoothAdapter.getDefaultAdapter().isEnabled() ? 1 : 0, + true)); + } + + // gps + LocationManager locationManager = (LocationManager) + context.getSystemService(Context.LOCATION_SERVICE); + boolean gpsEnabled = locationManager. + isProviderEnabled(LocationManager.GPS_PROVIDER); + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS, + gpsEnabled ? 1 : 0, true)); + + // wifi + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFI, + wifiManager.isWifiEnabled() ? 1 : 0, true)); + + // auto sync data + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_SYNC, + ContentResolver.getMasterSyncAutomatically() ? 1 : 0, true)); + + // mobile data + if (DeviceUtils.deviceSupportsMobileData(context)) { + ConnectivityManager cm = (ConnectivityManager) + context.getSystemService(Context.CONNECTIVITY_SERVICE); + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA, + cm.getMobileDataEnabled() ? 1 : 0, true)); + } + + // wifi hotspot + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFIAP, + wifiManager.isWifiApEnabled() ? 1 : 0, true)); + + // 2g/3g/4g + // skipping this one + + // nfc + if (DeviceUtils.deviceSupportsNfc(context)) { + NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE); + profile.setConnectionSettings( + new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_NFC, + nfcManager.getDefaultAdapter().isEnabled() ? 1 : 0, true)); + } + + // alarm volume + final AudioManager am = (AudioManager) context + .getSystemService(Context.AUDIO_SERVICE); + profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM, + am.getStreamVolume(AudioManager.STREAM_ALARM), true)); + + // media volume + profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC, + am.getStreamVolume(AudioManager.STREAM_MUSIC), true)); + + // ringtone volume + profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING, + am.getStreamVolume(AudioManager.STREAM_RING), true)); + + // notification volume + profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION, + am.getStreamVolume(AudioManager.STREAM_NOTIFICATION), true)); + + // ring mode + String ringValue; + switch (am.getRingerMode()) { + default: + case AudioManager.RINGER_MODE_NORMAL: + ringValue = "normal"; + break; + case AudioManager.RINGER_MODE_SILENT: + ringValue = "mute"; + break; + case AudioManager.RINGER_MODE_VIBRATE: + ringValue = "vibrate"; + break; + } + profile.setRingMode(new RingModeSettings(ringValue, true)); + + // airplane mode + boolean airplaneMode = Settings.Global.getInt(context.getContentResolver(), + Settings.Global.AIRPLANE_MODE_ON, 0) != 0; + profile.setAirplaneMode(new AirplaneModeSettings(airplaneMode ? 1 : 0, true)); + + // lock screen mode + // populated only from profiles, so we can read the current profile, + // but let's skip this one } private void requestRemoveProfileDialog() { diff --git a/src/com/android/settings/profiles/SetupDefaultProfileReceiver.java b/src/com/android/settings/profiles/SetupDefaultProfileReceiver.java new file mode 100644 index 0000000..10addf1 --- /dev/null +++ b/src/com/android/settings/profiles/SetupDefaultProfileReceiver.java @@ -0,0 +1,27 @@ +package com.android.settings.profiles; + +import android.app.Profile; +import android.app.ProfileManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.provider.Settings; + +public class SetupDefaultProfileReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + if (Settings.System.getInt(context.getContentResolver(), + Settings.System.SYSTEM_PROFILES_ENABLED, 1) == 1) { + ProfileManager profileManager = (ProfileManager) context + .getSystemService(Context.PROFILE_SERVICE); + Profile defaultProfile = profileManager.getProfile("Default"); + if (defaultProfile != null) { + SetupActionsFragment.fillProfileWithCurrentSettings(context, defaultProfile); + profileManager.updateProfile(defaultProfile); + } + } + + + } +} |