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

Commit 52483957 authored by Roman Birg's avatar Roman Birg
Browse files

Settings: setup Default Profile after OOBE has run



Change-Id: Ic961d5bfd041830baff4d6d73fc36762a1f6dfcf
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 093434d5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.HARDWARE_ABSTRACTION_ACCESS" />
    <uses-permission android:name="com.cyanogen.permission.REQUEST_KILL_SWITCH_OP" />
    <uses-permission android:name="cyanogenmod.permission.FINISH_SETUP" />

    <permission
        android:name="cyanogenmod.permission.PROTECTED_APP"
@@ -2358,5 +2359,11 @@
            </intent-filter>
        </activity>

        <receiver android:name=".profiles.SetupDefaultProfileReceiver">
            <intent-filter>
                <action android:name="com.cyanogenmod.setupwizard.SETUP_FINISHED" />
            </intent-filter>
        </receiver>

    </application>
</manifest>
+102 −100
Original line number Diff line number Diff line
@@ -361,12 +361,26 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
    }

    private void fillProfileFromCurrentSettings() {
        new AsyncTask<Profile, Void, Void>() {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Profile... params) {
            protected Void doInBackground(Void... params) {
                fillProfileWithCurrentSettings(getActivity(), mProfile);
                updateProfile();
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                rebuildItemList();
            }
        }.execute((Void) null);
    }

    public static void fillProfileWithCurrentSettings(Context context, Profile profile) {
        // bt
        if (DeviceUtils.deviceSupportsBluetooth()) {
                    mProfile.setConnectionSettings(
            profile.setConnectionSettings(
                    new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH,
                            BluetoothAdapter.getDefaultAdapter().isEnabled() ? 1 : 0,
                            true));
@@ -374,35 +388,35 @@ public class SetupActionsFragment extends SettingsPreferenceFragment

        // gps
        LocationManager locationManager = (LocationManager)
                        getSystemService(Context.LOCATION_SERVICE);
                context.getSystemService(Context.LOCATION_SERVICE);
        boolean gpsEnabled = locationManager.
                isProviderEnabled(LocationManager.GPS_PROVIDER);
                mProfile.setConnectionSettings(
        profile.setConnectionSettings(
                new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_GPS,
                        gpsEnabled ? 1 : 0, true));

        // wifi
                WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                mProfile.setConnectionSettings(
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        profile.setConnectionSettings(
                new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFI,
                        wifiManager.isWifiEnabled() ? 1 : 0, true));

        // auto sync data
                mProfile.setConnectionSettings(
        profile.setConnectionSettings(
                new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_SYNC,
                        ContentResolver.getMasterSyncAutomatically() ? 1 : 0, true));

        // mobile data
                if (DeviceUtils.deviceSupportsMobileData(getActivity())) {
        if (DeviceUtils.deviceSupportsMobileData(context)) {
            ConnectivityManager cm = (ConnectivityManager)
                            getSystemService(Context.CONNECTIVITY_SERVICE);
                    mProfile.setConnectionSettings(
                    context.getSystemService(Context.CONNECTIVITY_SERVICE);
            profile.setConnectionSettings(
                    new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA,
                            cm.getMobileDataEnabled() ? 1 : 0, true));
        }

        // wifi hotspot
                mProfile.setConnectionSettings(
        profile.setConnectionSettings(
                new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_WIFIAP,
                        wifiManager.isWifiApEnabled() ? 1 : 0, true));

@@ -410,29 +424,29 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
        // skipping this one

        // nfc
                if (DeviceUtils.deviceSupportsNfc(getActivity())) {
                    NfcManager nfcManager = (NfcManager) getSystemService(Context.NFC_SERVICE);
                    mProfile.setConnectionSettings(
        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) getActivity()
        final AudioManager am = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
                mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM,
        profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_ALARM,
                am.getStreamVolume(AudioManager.STREAM_ALARM), true));

        // media volume
                mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC,
        profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_MUSIC,
                am.getStreamVolume(AudioManager.STREAM_MUSIC), true));

        // ringtone volume
                mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING,
        profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_RING,
                am.getStreamVolume(AudioManager.STREAM_RING), true));

        // notification volume
                mProfile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION,
        profile.setStreamSettings(new StreamSettings(AudioManager.STREAM_NOTIFICATION,
                am.getStreamVolume(AudioManager.STREAM_NOTIFICATION), true));

        // ring mode
@@ -449,28 +463,16 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
                ringValue = "vibrate";
                break;
        }
                mProfile.setRingMode(new RingModeSettings(ringValue, true));
        profile.setRingMode(new RingModeSettings(ringValue, true));

        // airplane mode
                boolean airplaneMode = Settings.Global.getInt(getActivity().getContentResolver(),
        boolean airplaneMode = Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
                mProfile.setAirplaneMode(new AirplaneModeSettings(airplaneMode ? 1 : 0, true));
        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

                updateProfile();
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                rebuildItemList();

            }
        }.execute(mProfile);
    }

    private void requestRemoveProfileDialog() {
+27 −0
Original line number Diff line number Diff line
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);
            }
        }


    }
}