【CTA】CTA认证要求打开日历时提示联系人权限确认

国内过CTA认证时,要求打开日历时提示联系人权限确认,这里所说的联系人权限不是系统默认赋予的权限提示,而是需要新加一个权限提示内容,让用户进行确认。

平台:Android P(9.0)

修改代码如下:

vendor/mediatek/proprietary/packages/apps/Calendar/res/values-zh-rCN/strings.xml

--- a/alps/vendor/mediatek/proprietary/packages/apps/Calendar/res/values-zh-rCN/strings.xml
+++ b/alps/vendor/mediatek/proprietary/packages/apps/Calendar/res/values-zh-rCN/strings.xml
@@ -280,4 +280,11 @@
     "每月(每月的%1$s%2$s)"
+       
+       "日历会尝试取得您的联系人权限以供功能正常运行"
+       "允许"
+       "拒绝"
+       "读取联系人权限失败,拒绝访问日历"
+       
 

vendor/mediatek/proprietary/packages/apps/Calendar/src/com/android/calendar/AllInOneActivity.java

--- a/alps/vendor/mediatek/proprietary/packages/apps/Calendar/src/com/android/calendar/AllInOneActivity.java
+++ b/alps/vendor/mediatek/proprietary/packages/apps/Calendar/src/com/android/calendar/AllInOneActivity.java
@@ -95,6 +95,12 @@ import java.util.TimeZone;
 import java.util.Arrays;
 import java.util.ArrayList;
 
+//Monkey.20200410 CTA
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+//END
+
 import static android.provider.CalendarContract.Attendees.ATTENDEE_STATUS;
 import static android.provider.CalendarContract.EXTRA_EVENT_ALL_DAY;
 import static android.provider.CalendarContract.EXTRA_EVENT_BEGIN_TIME;
@@ -116,6 +122,11 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
     // @}
     private static final int HANDLER_KEY = 0;
     private static float mScale = 0;
+       
+       //Monkey.20200410 CTA
+       private final String CALENDAR_CONFIRM_PREF_NAME = "ConfirmPrefFile";
+       private final String CONFIRM_VALUE_KEY = "mtk_calendar_confirmed";
+       //END
 
     // Indices of buttons for the drop down menu (tabs replacement)
     // Must match the strings in the array buttons_list in arrays.xml and the
@@ -634,6 +645,10 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
                            "AllInOneActivity.onCreate.restoreState");
 
         mBundleIcicleOncreate = icicle;
+               
+               //Monkey.20200410 CTA
+               buildAndShowConfirmDialog();
+               //END
 
         if (!checkAndRequestPermission(CALENDAR_ONCREATE_PERMISSIONS_REQUEST_CODE))
         {
@@ -1878,4 +1893,48 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
             mSearchMenu.expandActionView();
         }
     }
+       
+       /**
+        * Monkey.20200410
+        * CTA Dialog
+        */
+       private void setConfirmed() {
+          SharedPreferences settings = getSharedPreferences(CALENDAR_CONFIRM_PREF_NAME, 0);
+          SharedPreferences.Editor editor = settings.edit();
+          editor.putBoolean(CONFIRM_VALUE_KEY, true);
+          editor.commit();
+       }
+
+       private boolean getConfirmed() {
+          SharedPreferences settings = getSharedPreferences(CALENDAR_CONFIRM_PREF_NAME, 0);
+          return settings.getBoolean(CONFIRM_VALUE_KEY, false);
+       }
+
+       private void buildAndShowConfirmDialog() {
+          if (!getConfirmed()) {
+                  Log.d(TAG, "buildAndShowConfirmDialog()");
+                  Dialog dialog = new AlertDialog.Builder(this)
+                          .setMessage(R.string.confirm_dialog_msg)
+                          .setPositiveButton(R.string.confirm_dialog_allow_button,
+                                          new DialogInterface.OnClickListener() {
+                                                  public void onClick(DialogInterface dialog, int whichButton) {
+                                                               setConfirmed();
+                                                  }
+                                          })
+                          .setNegativeButton(R.string.confirm_dialog_deny_button,
+                                          new DialogInterface.OnClickListener() {
+                                                  public void onClick(DialogInterface dialog, int whichButton) {
+                                                          Toast toast = Toast.makeText(getApplicationContext(), R.string.deny_toast_msg,
+                                                                  Toast.LENGTH_LONG);
+                                                          toast.show();
+                                                          finish();
+                                                  }
+                                          })
+                  .create();
+                  dialog.setCanceledOnTouchOutside(false);
+                  dialog.setCancelable(false);
+                  dialog.show();
+          }
+    }
 }

 

你可能感兴趣的:(Android,安卓,联系人,CTA,权限)