Show RingtonePickerActivity in work user instead

Test: make RunSettingsRoboTests
Test: Try to import custom ringtone in work profile, no crash observed
Test: Set the custom ringtone as default. Tested both work gmail and
      calendar can play that ringtone.
Test: Try to import the peresonal ringtone, it is still working.

Bug: 37197930
Change-Id: I2b662247d7e70b59bae08e082e9682d74d797484
This commit is contained in:
Tony Mak
2017-04-11 20:07:39 +01:00
parent 44cfdcc9a7
commit 007dc1abe6
4 changed files with 42 additions and 29 deletions

View File

@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings.System;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
@@ -54,6 +55,8 @@ public class RingtonePreference extends Preference {
private boolean mShowSilent;
private int mRequestCode;
protected int mUserId;
protected Context mUserContext;
public RingtonePreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -67,9 +70,19 @@ public class RingtonePreference extends Preference {
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
true);
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER));
setUserId(UserHandle.myUserId());
a.recycle();
}
public void setUserId(int userId) {
mUserId = userId;
mUserContext = Utils.createPackageContextAsUser(getContext(), mUserId);
}
public int getUserId() {
return mUserId;
}
/**
* Returns the sound type(s) that are shown in the picker.
*