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

Commit 9934a7e1 authored by David Bidorff's avatar David Bidorff Committed by Steve Kondik
Browse files

Phone Goggles: System settings

Phone Goggles provides to the end user the ability to filter its
outgoing communications and avoid any unwilling call or SMS to be
sent. Several settings can be configured: the way the user will
be informed that his communication has been blocked (and whether
or not is allowed to unlock the blocking), the period during which
the communications will be filtered, the type of phones that will
be filtered (Work, Mobile, Other)...

Latest commit:
 - Complete API that allows external APK to use the PhoneGoggles
   API without loosing the compatibility with non-CyanogenMod ROMs.
 - Better readability of the code (thanks to Volodymyr Lisivka) as
   Uthe I creation and the logic have been separated into several
   specialized methods.
 - The PhoneGoggles utility class now offers a single method
   'processCommunication' that will manage the entire process.
 - There are no traces of the former name (Drunk Mode) of the
   feature in the source code, I hope this will avoid any trouble
   related to the appearing lack of professionalism of the feature.
 - The user is now able to choose the kind of phone types he wants
   to filter (Work, Mobile, Other)
 - Corrections thanks to Evan Charlton (copyright added to the new
   classes, arrays translations are now in string.xml, no more
   useless comments and the typo on 'translatable="falses"' is
   fixed)

Using the PhoneGoggles API

 Here is how a developer can use Phone Goggles in his APK without breaking the
 compatibility with non-CyanogenMod ROMs:

 1) Add the following Intent Filter to the Activity that will call the Phone
    Goggles API, that way, the user will be able to configure it in the
    Settings.

    <intent-filter>
      <action android:name="android.intent.action.PHONE_GOGGLES_COMMUNICATION"/>
    </intent-filter>

 2) In your Activity or in an Util class of your APK (in the case where you
    use Phone Goggles in several Activities in the same APK), add these few
    lines. They will allow you to check if the Phone Goggles API is available.

    private static Method phoneGoggles;
    static {
      try {
        Class phoneGogglesClass = Class.forName("android.util.PhoneGoggles");
        phoneGoggles = phoneGogglesClass.getMethod("processCommunication",
           new Class[] {Context.class, int.class, String[].class,
                  Runnable.class, Runnable.class, int.class, int.class,
                  int.class, int.class, int.class, int.class});

      } catch (ClassNotFoundException e) {
      } catch (SecurityException e) {
      } catch (NoSuchMethodException e) {
      }
    }

 3) When you need to create a communication, simply do it like that:

    final Runnable onRun = new Runnable() {
      public void run() {
        // Perform the communication
      }
    };
    final Runnable onCancel = new Runnable() {
      public void run() {
        // Abandon the communication before even starting it
      }
    };

    if (phoneGoggles != null) {
      try {
        phoneGoggles.invoke(null, this,
           1,         // 1 for phone numbers
                      // 2 for email addresses
                      // 0 otherwise
           numbers,   // a String[] containing the phone numbers OR the
                      // email addresses of the contacts
           onRun, onCancel,
           R.string.dialog_phone_goggles_title,           // Values to be
           R.string.dialog_phone_goggles_title_unlocked,  // defined in the
           R.string.dialog_phone_goggles_content,         // string.xml files
           R.string.dialog_phone_goggles_unauthorized,
           R.string.dialog_phone_goggles_ok,
           R.string.dialog_phone_goggles_cancel);

      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }

    // If the Phone Goggles API doesn't exist
    } else {
      onRun.run();
    }

Change-Id: Ib62808302c6a27e19d600567e9bf854d15732945
parent c7beef0e
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -2311,6 +2311,68 @@ public final class Settings {
        public static final String OVERSCROLL_WEIGHT = "overscroll_weight";


        /**
         * Whether the phone goggles mode is enabled or not.
         * @hide
         */
        public static final String PHONE_GOGGLES_ENABLED = "phone_goggles_enabled";

        /**
         * Which confirmation mode is used for phone goggles.
         * @hide
         */
        public static final String PHONE_GOGGLES_CONFIRMATION_MODE =
            "phone_goggles_confirmation_mode";

        /**
         * Whether the application use custom settings for PhoneGoggles or not.
         * @hide
         */
        public static final String PHONE_GOGGLES_USE_CUSTOM = "phone_goggles_use_custom";

        /**
         * Sets when phone goggles start. This is stored in minutes from the start of the day.
         * @hide
         */
        public static final String PHONE_GOGGLES_START = "phone_goggles_start";

        /**
         * Sets when phone goggles end. This is stored in minutes from the start of the day.
         * @hide
         */
        public static final String PHONE_GOGGLES_END = "phone_goggles_end";

        /**
         * Whether the phone goggles mode is enabled or not for an app.
         * @hide
         */
        public static final String PHONE_GOGGLES_APP_ENABLED =
            "phone_goggles_app_enabled";

        /**
         * Level of the maths problems asked by the phone goggles.
         * @hide
         */
        public static final String PHONE_GOGGLES_MATHS_LEVEL = "phone_goggles_maths_level";

        /**
         * Indicates if the work numbers must be filtered by phone goggles.
         * @hide
         */
        public static final String PHONE_GOGGLES_WORK_FILTERED = "phone_goggles_work_filtered";

        /**
         * Indicates if the mobile numbers must be filtered by phone goggles.
         * @hide
         */
        public static final String PHONE_GOGGLES_MOBILE_FILTERED = "phone_goggles_mobile_filtered";

        /**
         * Indicates if the other numbers must be filtered by phone goggles.
         * @hide
         */
        public static final String PHONE_GOGGLES_OTHER_FILTERED = "phone_goggles_other_filtered";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+548 −0

File added.

Preview size limit exceeded, changes collapsed.

+53 −0

File added.

Preview size limit exceeded, changes collapsed.

+8 −0
Original line number Diff line number Diff line
@@ -913,4 +913,12 @@
    <string name="media_unknown_state" msgid="729192782197290385">"État du support externe inconnu"</string>
    <!--Application killed toast -->
    <string name="app_killed_message">Application tuée</string>

    <!-- Phone goggles -->
    <string name="phone_goggles_problem_count">Problème #%1$d : </string>
    <string name="phone_goggles_description">Répondez aux %1$d problèmes mathématiques suivants en moins de %2$d secondes pour autoriser la communication.</string>
    <plurals name="phone_goggles_countdown">
        <item quantity="one">%d seconde restante</item>
        <item quantity="other">%d secondes restantes</item>
    </plurals>
</resources>
+8 −0

File changed.

Preview size limit exceeded, changes collapsed.