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:
@@ -19,40 +19,15 @@ package com.android.settings;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class DefaultRingtonePreference extends RingtonePreference {
|
public class DefaultRingtonePreference extends RingtonePreference {
|
||||||
private static final String TAG = "DefaultRingtonePreference";
|
private static final String TAG = "DefaultRingtonePreference";
|
||||||
|
|
||||||
private int mUserId = UserHandle.USER_CURRENT;
|
|
||||||
protected Context mUserContext;
|
|
||||||
|
|
||||||
public DefaultRingtonePreference(Context context, AttributeSet attrs) {
|
public DefaultRingtonePreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mUserContext = getContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(int userId) {
|
|
||||||
mUserId = userId;
|
|
||||||
mUserContext = Utils.createPackageContextAsUser(getContext(), mUserId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void performClick() {
|
|
||||||
if (mUserId != UserHandle.USER_CURRENT) {
|
|
||||||
if (Utils.confirmWorkProfileCredentialsIfNecessary(getContext(), mUserId) ||
|
|
||||||
Utils.startQuietModeDialogIfNecessary(getContext(),
|
|
||||||
UserManager.get(getContext()), mUserId)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.performClick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,9 +39,6 @@ public class DefaultRingtonePreference extends RingtonePreference {
|
|||||||
* doesn't make sense to show a 'Default' item.
|
* doesn't make sense to show a 'Default' item.
|
||||||
*/
|
*/
|
||||||
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
|
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
|
||||||
if (mUserId != UserHandle.USER_CURRENT) {
|
|
||||||
ringtonePickerIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.media.AudioAttributes;
|
import android.media.AudioAttributes;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings.System;
|
import android.provider.Settings.System;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
@@ -54,6 +55,8 @@ public class RingtonePreference extends Preference {
|
|||||||
private boolean mShowSilent;
|
private boolean mShowSilent;
|
||||||
|
|
||||||
private int mRequestCode;
|
private int mRequestCode;
|
||||||
|
protected int mUserId;
|
||||||
|
protected Context mUserContext;
|
||||||
|
|
||||||
public RingtonePreference(Context context, AttributeSet attrs) {
|
public RingtonePreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -67,9 +70,19 @@ public class RingtonePreference extends Preference {
|
|||||||
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
|
mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent,
|
||||||
true);
|
true);
|
||||||
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER));
|
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER));
|
||||||
|
setUserId(UserHandle.myUserId());
|
||||||
a.recycle();
|
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.
|
* Returns the sound type(s) that are shown in the picker.
|
||||||
*
|
*
|
||||||
|
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.preference.SeekBarVolumizer;
|
import android.preference.SeekBarVolumizer;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -85,7 +86,11 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
if (preference instanceof RingtonePreference) {
|
if (preference instanceof RingtonePreference) {
|
||||||
mRequestPreference = (RingtonePreference) preference;
|
mRequestPreference = (RingtonePreference) preference;
|
||||||
mRequestPreference.onPrepareRingtonePickerIntent(mRequestPreference.getIntent());
|
mRequestPreference.onPrepareRingtonePickerIntent(mRequestPreference.getIntent());
|
||||||
startActivityForResult(preference.getIntent(), REQUEST_CODE);
|
startActivityForResultAsUser(
|
||||||
|
mRequestPreference.getIntent(),
|
||||||
|
REQUEST_CODE,
|
||||||
|
null,
|
||||||
|
UserHandle.of(mRequestPreference.getUserId()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onPreferenceTreeClick(preference);
|
return super.onPreferenceTreeClick(preference);
|
||||||
|
@@ -27,6 +27,7 @@ import android.telephony.TelephonyManager;
|
|||||||
|
|
||||||
import com.android.settings.DefaultRingtonePreference;
|
import com.android.settings.DefaultRingtonePreference;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.RingtonePreference;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
|
||||||
@@ -251,4 +252,26 @@ public class WorkSoundPreferenceControllerTest {
|
|||||||
verify(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
|
verify(mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
|
||||||
.setSummary(eq(notAvailable));
|
.setSummary(eq(notAvailable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onResume_shouldSetUserIdToPreference() {
|
||||||
|
final int managedProfileUserId = 10;
|
||||||
|
when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
|
||||||
|
.thenReturn(managedProfileUserId);
|
||||||
|
when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
|
||||||
|
when(mAudioHelper.isSingleVolume()).thenReturn(false);
|
||||||
|
when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
|
||||||
|
when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
mController.onResume();
|
||||||
|
|
||||||
|
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE))
|
||||||
|
.setUserId(managedProfileUserId);
|
||||||
|
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_NOTIFICATION_RINGTONE))
|
||||||
|
.setUserId(managedProfileUserId);
|
||||||
|
verify((RingtonePreference) mWorkCategory.findPreference(KEY_WORK_ALARM_RINGTONE))
|
||||||
|
.setUserId(managedProfileUserId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user