--- a/alps/frameworks/base/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
+++ b/alps/frameworks/base/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
@@ -43,6 +43,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import android.os.SystemProperties;
+
import static android.os.Process.FIRST_APPLICATION_UID;
/**
@@ -612,6 +614,9 @@ final class DefaultPermissionGrantPolicy {
/* removed for xts testDefaultGrants test at 20160627
Music close STORAGE_PERMISSIONS by default */
// grantRuntimePermissionsLPw(musicPackage, STORAGE_PERMISSIONS, userId);
+ if (SystemProperties.get("ro.music_multisim_ringtone").equals("1")){
+ grantRuntimePermissionsLPw(musicPackage, PHONE_PERMISSIONS, userId);
+ }
}
mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId);
diff --git a/alps/packages/apps/Music/res/values-fr/strings.xml b/alps/packages/apps/Music/res/values-fr/strings.xml
old mode 100644
new mode 100755
index 5168838..4d31478
--- a/alps/packages/apps/Music/res/values-fr/strings.xml
+++ b/alps/packages/apps/Music/res/values-fr/strings.xml
@@ -150,4 +150,7 @@
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"Appuyez pour sélectionner des titres"
"Effets sonores"
+
+ utilisation comme sim1 sonnerie
+ utilisation comme sim2 sonnerie
\ No newline at end of file
diff --git a/alps/packages/apps/Music/res/values-zh-rCN/strings.xml b/alps/packages/apps/Music/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index 8abea51..df7615f
--- a/alps/packages/apps/Music/res/values-zh-rCN/strings.xml
+++ b/alps/packages/apps/Music/res/values-zh-rCN/strings.xml
@@ -153,4 +153,7 @@
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"触摸可选择音乐。"
"音效"
+
+ 用作SIM1手机铃声
+ 用作SIM2手机铃声
diff --git a/alps/packages/apps/Music/res/values/strings.xml b/alps/packages/apps/Music/res/values/strings.xml
old mode 100644
new mode 100755
index 37e5a4c..c94f1c3
--- a/alps/packages/apps/Music/res/values/strings.xml
+++ b/alps/packages/apps/Music/res/values/strings.xml
@@ -314,5 +314,8 @@
Permission denied. You can change permissions in Settings->Apps.
+
+ Use as SIM1 ringtone
+ Use as SIM2 ringtone
--- a/alps/packages/apps/Music/src/com/android/music/MediaPlaybackActivity.java
+++ b/alps/packages/apps/Music/src/com/android/music/MediaPlaybackActivity.java
@@ -85,6 +85,13 @@ import android.widget.Toast;
import com.android.music.MusicUtils.ServiceToken;
import com.mediatek.drm.OmaDrmStore;
+// start modify Music MultiSim
+import android.telephony.TelephonyManager;
+import android.telephony.SubscriptionManager;
+import android.os.SystemProperties;
+import java.util.List;
+import android.content.pm.PackageManager;
+import android.Manifest;
+// end modify Music MultiSim
+
public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
View.OnTouchListener, View.OnLongClickListener, CreateBeamUrisCallback
{
@@ -709,8 +716,25 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
if (MusicUtils.isVoiceCapable(this)) {
+ //start modify Music MultiSim
+ if(SystemProperties.get("ro.mtk_audio_profiles").equals("1") && SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ MusicLogUtils.d(TAG, "simNum:" + simNum);
+
+ if(simNum==2){
+ menu.add(0, USE_AS_SIM1_RINGTONE, 0, R.string.ringtone_as_sim1_menu).setIcon(
+ R.drawable.ic_menu_set_as_ringtone);
+ menu.add(0, USE_AS_SIM2_RINGTONE, 0, R.string.ringtone_as_sim2_menu).setIcon(
+ R.drawable.ic_menu_set_as_ringtone);
+ }else {
+ menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short).setIcon(
+ R.drawable.ic_menu_set_as_ringtone);
+ }
+ }else
+ //end modify Music MultiSim
menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu_short).setIcon(
- R.drawable.ic_menu_set_as_ringtone);
+ R.drawable.ic_menu_set_as_ringtone);
}
}
@@ -787,16 +811,53 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
/// M: DRM feature, when track is drm and not FL type, it can not set as ringtone. {@
if (MusicFeatureOption.IS_SUPPORT_DRM && MusicUtils.isVoiceCapable(this)) {
try {
- menu.findItem(USE_AS_RINGTONE).setVisible(mService.canUseAsRingtone());
+ //MultiSim begin
+ if(SystemProperties.get("ro.mtk_audio_profiles").equals("1") && SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ MusicLogUtils.d(TAG, "Prepare simNum:" + simNum);
+ if(simNum==2){
+ menu.findItem(USE_AS_SIM1_RINGTONE).setVisible(mService.canUseAsRingtone());
+ menu.findItem(USE_AS_SIM2_RINGTONE).setVisible(mService.canUseAsRingtone());
+ }else
+ menu.findItem(USE_AS_RINGTONE).setVisible(mService.canUseAsRingtone());
+
+ }else
+ //MultiSim end
+ menu.findItem(USE_AS_RINGTONE).setVisible(mService.canUseAsRingtone());
} catch (RemoteException e) {
MusicLogUtils.e(TAG, "onPrepareOptionsMenu with RemoteException " + e);
}
}
} else {
- MenuItem ringtoneItem = menu.findItem(USE_AS_RINGTONE);
- if (ringtoneItem != null) {
- ringtoneItem.setVisible(false);
- }
+ //MultiSim begin
+ if(SystemProperties.get("ro.mtk_audio_profiles").equals("1") && SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ MusicLogUtils.d(TAG, "Prepare simNum:" + simNum);
+ if(simNum==2){
+ MenuItem ringtoneItem1 = menu.findItem(USE_AS_SIM1_RINGTONE);
+ MenuItem ringtoneItem2 = menu.findItem(USE_AS_SIM2_RINGTONE);
+ if (ringtoneItem1 != null) {
+ ringtoneItem1.setVisible(false);
+ }
+ if (ringtoneItem2 != null) {
+ ringtoneItem2.setVisible(false);
+ }
+ }else{
+ MenuItem ringtoneItem = menu.findItem(USE_AS_RINGTONE);
+ if (ringtoneItem != null) {
+ ringtoneItem.setVisible(false);
+ }
+ }
+ }else
+ //MultiSim end
+ {
+ MenuItem ringtoneItem = menu.findItem(USE_AS_RINGTONE);
+ if (ringtoneItem != null) {
+ ringtoneItem.setVisible(false);
+ }
+ }
}
/**@}**/
/// M: Set effect menu visible depend the effect class whether disable or enable. {@
@@ -790,6 +793,17 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
}
return false;
}
+
+ //add
+ private boolean hasPhonePermission(){
+ int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED){
+ return false;
+ }
+ else{
+ return true;
+ }
+ }
@@ -866,13 +927,39 @@ public class MediaPlaybackActivity extends Activity implements MusicUtils.Defs,
startActivity(intent);
finish();
break;
- case USE_AS_RINGTONE: {
+ case USE_AS_RINGTONE: {
// Set the system setting to make this the current ringtone
- if (mService != null) {
- MusicUtils.setRingtone(this, mService.getAudioId());
+ if (mService != null) {
+ //start modify Music MultiSim
+ /**/ if (SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ int[] mSubIdList = SubscriptionManager.from(this).getActiveSubscriptionIdList();
+ MusicUtils.setRingtone(this, mService.getAudioId(),mSubIdList[0]);
+ }else
+ //end modify Music MultiSim
+ MusicUtils.setRingtone(this, mService.getAudioId(),-1);
}
return true;
}
+ //start modify Music MultiSim
+ case USE_AS_SIM1_RINGTONE: {
+ // Set the system setting to make this the current ringtone
+ /* */if (mService != null) {
+ int subId=SubscriptionManager.getSubId(0)[0];
+ MusicLogUtils.d(TAG, "onOptionsItemSelected +++ subId= " + subId);
+ MusicUtils.setRingtone(this, mService.getAudioId(),subId);
+ }
+ return true;
+ }
+ case USE_AS_SIM2_RINGTONE: {
+ // Set the system setting to make this the current ringtone
+ if (mService != null) {
+ int subId=SubscriptionManager.getSubId(1)[0];
+ MusicLogUtils.d(TAG, "onOptionsItemSelected ++ subId= " + subId);
+ MusicUtils.setRingtone(this, mService.getAudioId(),subId);
+ } /* */
+ return true;
+ }
+ //end modify Music MultiSim
case PARTY_SHUFFLE:
MusicUtils.togglePartyShuffle();
setShuffleButtonImage();
diff --git a/alps/packages/apps/Music/src/com/android/music/MusicUtils.java b/alps/packages/apps/Music/src/com/android/music/MusicUtils.java
old mode 100644
new mode 100755
index 562a67d..d53ed1e
--- a/alps/packages/apps/Music/src/com/android/music/MusicUtils.java
+++ b/alps/packages/apps/Music/src/com/android/music/MusicUtils.java
@@ -86,6 +86,14 @@ import android.widget.Toast;
import android.telephony.TelephonyManager;
+//start modify Music MultiSim
+import android.telephony.TelephonyManager;
+import com.mediatek.audioprofile.AudioProfileManager;
+import android.os.SystemProperties;
+import android.telephony.SubscriptionManager;
+//end modify Music MultiSim
+
+
public class MusicUtils {
private static final String TAG = "MusicUtils";
@@ -136,7 +144,12 @@ public class MusicUtils {
public final static int FM_TRANSMITTER = 14;
/// M: add for drm
public final static int DRM_INFO = 15;
- public final static int CHILD_MENU_BASE = 16; // this should be the last item
+ //start modify Music MultiSim
+ public final static int USE_AS_SIM1_RINGTONE = 16;
+ public final static int USE_AS_SIM2_RINGTONE = 17;
+ public final static int CHILD_MENU_BASE = 18; // this should be the last item
+ // public final static int CHILD_MENU_BASE = 16; // this should be the last item
+ //end modify Music MultiSim
/**M: Add Hotknot menu.@{**/
public final static int HOTKNOT = CHILD_MENU_BASE + 10;
/**@}**/
@@ -1330,7 +1343,7 @@ public class MusicUtils {
SharedPreferencesCompat.apply(ed);
}
- static void setRingtone(Context context, long id) {
+ static void setRingtone(Context context, long id,int slotId /* modify Music MultiSim */) {
ContentResolver resolver = context.getContentResolver();
// Set the flag in the database to mark this as a ringtone
Uri ringUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);
@@ -1360,6 +1373,21 @@ public class MusicUtils {
if (cursor != null && cursor.getCount() == 1) {
// Set the system setting to make this the current ringtone
cursor.moveToFirst();
+ //start modify Music MultiSim
+ if(SystemProperties.get("ro.music_multisim_ringtone").equals("1")){
+ AudioProfileManager mProfileManager = (AudioProfileManager) context.getSystemService(Context.AUDIO_PROFILE_SERVICE);
+ String mActiveProfileKey = mProfileManager.getActiveProfileKey();
+ final TelephonyManager mTeleManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ if(slotId == -1){
+ Settings.System.putString(resolver, Settings.System.RINGTONE, ringUri.toString());
+ MusicLogUtils.d(TAG, "setRingtone: " + "slotId is null" + ", ringUri= "+ringUri);
+
+ }else {
+ MusicLogUtils.d(TAG, "setRingtone: " + "slotId = " + slotId + ", ringUri= "+ringUri);
+ mProfileManager.setRingtoneUri(mActiveProfileKey, AudioProfileManager.TYPE_RINGTONE, slotId, ringUri);
+ }
+ }else
+ //end modify Music MultiSim
Settings.System.putString(resolver, Settings.System.RINGTONE, ringUri.toString());
String message = context.getString(R.string.ringtone_set, cursor.getString(2));
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
diff --git a/alps/packages/apps/Music/src/com/android/music/TrackBrowserActivity.java b/alps/packages/apps/Music/src/com/android/music/TrackBrowserActivity.java
old mode 100644
new mode 100755
index 772743a..24971a4
--- a/alps/packages/apps/Music/src/com/android/music/TrackBrowserActivity.java
+++ b/alps/packages/apps/Music/src/com/android/music/TrackBrowserActivity.java
@@ -91,6 +91,16 @@ import com.mediatek.drm.OmaDrmUiUtils;
//import java.text.Collator;
import java.util.Arrays;
+
+// start modify Music MultiSim
+import android.telephony.TelephonyManager;
+import android.telephony.SubscriptionManager;
+import android.os.SystemProperties;
+import android.telephony.SubscriptionInfo;
+import java.util.List;
+import android.content.pm.PackageManager;
+import android.Manifest;
+// end modify Music MultiSim
+
+
public class TrackBrowserActivity extends ListActivity
implements View.OnCreateContextMenuListener, MusicUtils.Defs,
ServiceConnection, DialogInterface.OnClickListener
@@ -936,6 +938,16 @@ public class TrackBrowserActivity extends ListActivity
}
return ismusic;
}
+
+
+ //add
+ private boolean hasPhonePermission(){
+ int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_PHONE_STATE);
+ if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED)
+ return false;
+ else
+ return true;
+ }
@@ -958,10 +968,34 @@ public class TrackBrowserActivity extends ListActivity
int drmMethod = mTrackCursor.getInt(mTrackCursor.getColumnIndexOrThrow
(MediaStore.Audio.Media.DRM_METHOD));
if (isVoiceCapable && canDispalyRingtone(isDrm, drmMethod)) {
+ //start modify Music MultiSim
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ MusicLogUtils.d(TAG, "simNum---------:" + simNum);
+ if(SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ if(simNum==2){
+ menu.add(0, USE_AS_SIM1_RINGTONE, 0, R.string.ringtone_as_sim1_menu);//ringtone_as_sim1_menu
+ menu.add(0, USE_AS_SIM2_RINGTONE, 0, R.string.ringtone_as_sim2_menu);//ringtone_as_sim2_menu
+ }else {
+ menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
+ }
+ }else //end modify Music MultiSim
menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
}
} else {
if (isVoiceCapable) {
+ //start modify Music MultiSim
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ MusicLogUtils.d(TAG, "simNum-----:" + simNum);
+ if(SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ final TelephonyManager mTeleManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
+ int simNum = SubscriptionManager.from(this).getActiveSubscriptionInfoCount();
+ if(simNum==2){
+ menu.add(0, USE_AS_SIM1_RINGTONE, 0, R.string.ringtone_as_sim1_menu);//ringtone_as_sim1_menu
+ menu.add(0, USE_AS_SIM2_RINGTONE, 0, R.string.ringtone_as_sim2_menu);//ringtone_as_sim2_menu
+ }else if(simNum==1){
+ menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
+ }
+ }else //end modify Music MultiSim
menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
}
}
@@ -1048,8 +1082,29 @@ public class TrackBrowserActivity extends ListActivity
case USE_AS_RINGTONE:
// Set the system setting to make this the current ringtone
- MusicUtils.setRingtone(this, mSelectedId);
+ //start modify Music MultiSim
+ if (SystemProperties.get("ro.music_multisim_ringtone").equals("1") && hasPhonePermission()){
+ int[] mSubIdList = SubscriptionManager.from(this).getActiveSubscriptionIdList();
+ MusicUtils.setRingtone(this,mService.getAudioId(),mSubIdList[0]);
+ }else/* */
+ //end modify Music MultiSim
+ MusicUtils.setRingtone(this, mSelectedId,-1);
return true;
+
+ //start modify Music MultiSim
+ case USE_AS_SIM1_RINGTONE:
+ // Set the system setting to make this the current ringtone1
+ int subId=SubscriptionManager.getSubId(0)[0];
+ MusicLogUtils.d(TAG, "onContextItemSelected subId= " + subId);
+ MusicUtils.setRingtone(this, mSelectedId,subId);
+ return true;
+ case USE_AS_SIM2_RINGTONE:
+ // Set the system setting to make this the current ringtone2
+ int subId1=SubscriptionManager.getSubId(1)[0];
+ MusicLogUtils.d(TAG, "onContextItemSelected subId= " + subId1);
+ MusicUtils.setRingtone(this, mSelectedId,subId1);
+ return true;
+ //end modify Music MultiSim
case DELETE_ITEM: {
long [] list = new long[1];