Merge changes Ie01dfc5c,Ie89c4ae1 into fp2-dev-v2

* changes:
  FP2-1335: Inconsistent layout clock widget
  FP2-1317: LockScreen Clock does not update when language changes
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index bef76c7..3b0bd2f 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -2440,7 +2440,9 @@
             Log.i(TAG_TIMELINE, "Timeline: Activity_launch_request id:"
                 + intent.getComponent().getPackageName() + " time:"
                 + SystemClock.uptimeMillis());
-            intent = wrapPrivacyImpact(intent, options, requestCode);
+            if(!callingPackage.equals("com.fairphone.privacyimpact")){
+                intent = wrapPrivacyImpact(intent, options, requestCode);
+            }
         }
 
         data.writeInterfaceToken(IActivityManager.descriptor);
diff --git a/core/res/res/xml/power_profile.xml b/core/res/res/xml/power_profile.xml
index 3215e17..e4fe0e0 100644
--- a/core/res/res/xml/power_profile.xml
+++ b/core/res/res/xml/power_profile.xml
@@ -57,7 +57,7 @@
       <value>0.1</value>  <!-- ~100mA -->
   </array>
   <!-- This is the battery capacity in mAh (measured at nominal voltage) -->
-  <item name="battery.capacity">1000</item>
+  <item name="battery.capacity">2420</item>
 
   <array name="wifi.batchedscan"> <!-- mA -->
       <value>.0002</value> <!-- 1-8/hr -->
diff --git a/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/GrantAccessActivity.java b/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/GrantAccessActivity.java
index f65212d..4bf9e7d 100644
--- a/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/GrantAccessActivity.java
+++ b/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/GrantAccessActivity.java
@@ -1,5 +1,6 @@
 package com.fairphone.privacyimpact;
 
+import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -34,107 +35,114 @@
     private static final String PREFS_PRIVACY_IMPACT = "com.fairphone.privacyimpact.PREFS_PRIVACY_IMPACT";
     private static final String SHOW_PRIVACY_IMPACT_OOBE = "com.fairphone.privacyimpact.SHOW_PRIVACY_OOBE";
     private static final boolean DEBUG = false;
+    
     public static final String HIDE_PRIVACY_IMPACT_PREFERENCE = "hide_privacy_impact_preference";
 
-    private AppSettingsDatabaseHelper mDatabase;
-    private Intent mOriginalIntent;
-    private Bundle mOptions;
-
-    private PrivacyImpactCalculator.PRIVACY_LEVEL mPrivacyLevel;
-    private SharedPreferences mSharedPrefs;
-    private SharedPreferences mDefaultSharedPreferences;
-
-
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-	try {
-	        // setup the database
-	        mDatabase = new AppSettingsDatabaseHelper(this);
-
-	        mDefaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-	        // treat the launch intent
-	        processLaunchIntent(getIntent());
-
-	        mSharedPrefs = getSharedPreferences(PREFS_PRIVACY_IMPACT, Context.MODE_PRIVATE);
-	        // setup the layout
-	        setupLayout();
-	} catch (Exception e) {
-		Log.e(TAG, "Failed to create Privacy Impact screen", e);
-	}
-    }
-
-    private void processLaunchIntent(Intent intent) {
-        Log.wtf(TAG, "GrantAccessActivity - start processLaunchIntent --------------------------------------");
-        Intent mLastPermissionsIntent = intent;
-
-        Bundle extras = mLastPermissionsIntent.getExtras();
-
-        Log.wtf(TAG, "GrantAccessActivity - Count : " + extras.size());
-
-        for (String key : extras.keySet()) {
-            String result = "";
-            if (extras.get(key) != null) {
-                result = extras.get(key).toString();
+    protected void onCreate(Bundle savedInstance) {
+        super.onCreate(savedInstance);
+        Log.wtf(TAG, "GrantAccessActivity - onCreate");
+        try {
+            Intent startIntent = getIntent();
+            
+            if (showPrivacyImpact(startIntent)) {
+                 Log.wtf(TAG, "if");
+                try {
+                    // setup the layout
+                    setupLayout(startIntent);
+                } catch (Exception e) {
+                    Log.e(TAG, "Failed to setup Privacy Impact screen", e);
+                    startApplication(startIntent);
+                }
+            } else {
+                Log.wtf(TAG, "else");
+                startApplication(startIntent);
             }
 
-            Log.wtf(TAG, "Key : " + key + " type " + result);
+        } catch (Exception e) {
+            Log.e(TAG, "Failed to launch Privacy Impact", e);
         }
-
-
-        mOriginalIntent = (Intent) extras.get("originalIntent");
-
-        Log.wtf(TAG, "GrantAccessActivity - " + mOriginalIntent.getComponent().getPackageName());
-        ;
-
-        boolean hidePrivacyImpact = mDefaultSharedPreferences.getBoolean(HIDE_PRIVACY_IMPACT_PREFERENCE, false);
-        if (mDatabase.isPackageEnable(mOriginalIntent.getComponent().getPackageName()) ||
-                hidePrivacyImpact ||
-                (mOriginalIntent.resolveActivityInfo(getPackageManager(), 0).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {
-
-            Log.i(TAG, "GrantAccessActivity - Package is enabled ------------------------------ ");
-
-            mOptions = (Bundle) extras.get("originalOptions");
-
-            startApplication(mOriginalIntent, mOptions);
-        }
-
-        Log.wtf(TAG, "GrantAccessActivity - end processLaunchIntent --------------------------------------");
     }
 
-    private void setupLayout() {
+    private boolean showPrivacyImpact(final Intent startIntent) {
+        Log.wtf(TAG, "GrantAccessActivity - start showPrivacyImpact");
+        
+        Bundle extras = startIntent.getExtras();
+        Intent originalIntent = (Intent) extras.get("originalIntent");
+        Bundle originalOptions = (Bundle) extras.get("originalOptions");
+        int originalRequestCode = (int) extras.get("originalRequestCode");
+
+        // log intent extras
+        if (DEBUG) {
+            Log.d(TAG, "GrantAccessActivity - Count : " + extras.size());
+    
+            for (String key : extras.keySet()) {
+                String result = "";
+                if (extras.get(key) != null) {
+                    result = extras.get(key).toString();
+                }
+    
+                Log.d(TAG, "Key : " + key + " type " + result);
+            }
+        }
+
+        Log.i(TAG, "GrantAccessActivity - " + originalIntent.getComponent().getPackageName());
+
+        // Is the hide popup preference checked?
+        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+        boolean popupDisabled = defaultSharedPreferences.getBoolean(HIDE_PRIVACY_IMPACT_PREFERENCE, false);
+
+        // Has it been validated already?
+        boolean impactAccepted =
+            AppSettingsDatabaseHelper.isPackageEnable(originalIntent.getComponent().getPackageName());
+        
+        // Is it a system app?
+        boolean isSystemApp = (originalIntent.resolveActivityInfo(getPackageManager(), 0).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM;
+        
+        boolean showPrivacyImpact = !popupDisabled && !impactAccepted && !isSystemApp;
+        
+        Log.d(TAG, "popupDisabled "+popupDisabled);
+        Log.d(TAG, "impactAccepted "+impactAccepted);
+        Log.d(TAG, "isSystemApp "+isSystemApp);
+        
+        Log.i(TAG, "GrantAccessActivity - "+(showPrivacyImpact ? "show popup" : "skip popup"));
+        return showPrivacyImpact;
+    }
+
+    private void setupLayout(Intent startIntent) {
         setContentView(R.layout.activity_grant_access);
 
-        final FrameLayout oobeGroup = (FrameLayout) findViewById(R.id.oobe_group);
-        if (mSharedPrefs.getBoolean(SHOW_PRIVACY_IMPACT_OOBE, true)) {
-            final View privacyOobePopup = findViewById(R.id.privacy_oobe_popup);
-            TextView privacyOobeButton = (TextView) findViewById(R.id.privacy_got_it);
-            final View notificationsOobePopup = findViewById(R.id.notifications_oobe_popup);
-            TextView notificationsOobeButton = (TextView) findViewById(R.id.notifications_got_it);
-
-            privacyOobeButton.setOnClickListener(new View.OnClickListener() {
+        SharedPreferences sharedPrefs = getSharedPreferences(PREFS_PRIVACY_IMPACT, Context.MODE_PRIVATE);
+        if (sharedPrefs.getBoolean(SHOW_PRIVACY_IMPACT_OOBE, true)) {
+            View privacyOobeButton = findViewById(R.id.privacy_got_it);
+            privacyOobeButton.setOnClickListener(new OnClickListenerInActivity(this) {
                 @Override
                 public void onClick(View v) {
-                    privacyOobePopup.setVisibility(View.GONE);
-                    notificationsOobePopup.setVisibility(View.VISIBLE);
+                    mActivity.findViewById(R.id.privacy_oobe_popup).setVisibility(View.GONE);
+                    mActivity.findViewById(R.id.notifications_oobe_popup).setVisibility(View.VISIBLE);
                 }
             });
 
-            notificationsOobeButton.setOnClickListener(new View.OnClickListener() {
+            View notificationsOobeButton = findViewById(R.id.notifications_got_it);
+            notificationsOobeButton.setOnClickListener(new OnClickListenerInActivity(this) {
                 @Override
                 public void onClick(View v) {
-                    notificationsOobePopup.setVisibility(View.GONE);
-                    oobeGroup.setVisibility(View.GONE);
-                    SharedPreferences.Editor editor = mSharedPrefs.edit();
+                    mActivity.findViewById(R.id.notifications_oobe_popup).setVisibility(View.GONE);
+                    mActivity.findViewById(R.id.oobe_group).setVisibility(View.GONE);
+                    SharedPreferences sharedPrefs = mActivity.getSharedPreferences(PREFS_PRIVACY_IMPACT, Context.MODE_PRIVATE);
+                    SharedPreferences.Editor editor = sharedPrefs.edit();
                     editor.putBoolean(SHOW_PRIVACY_IMPACT_OOBE, false);
                     editor.apply();
                 }
             });
         } else {
+            View oobeGroup = findViewById(R.id.oobe_group);
             oobeGroup.setVisibility(View.GONE);
         }
 
-        final ComponentName component = mOriginalIntent.getComponent();
+
+        Intent originalIntent = (Intent) startIntent.getExtras().get("originalIntent");
+        ComponentName component = originalIntent.getComponent();
 
         PackageManager pm = getPackageManager();
 
@@ -142,35 +150,40 @@
         ImageView mAppIcon = (ImageView) findViewById(R.id.app_icon);
 
         try {
-            mAppIcon.setImageDrawable(pm.getActivityIcon(mOriginalIntent));
+            mAppIcon.setImageDrawable(pm.getActivityIcon(originalIntent));
         } catch (PackageManager.NameNotFoundException e) {
             e.printStackTrace();
         }
 
 
         // setup the app name
-        TextView mAppName = (TextView) findViewById(R.id.app_name);
+        TextView appName = (TextView) findViewById(R.id.app_name);
         try {
-            mAppName.setText(pm.getActivityInfo(component, 0).loadLabel(pm));
+            appName.setText(pm.getActivityInfo(component, 0).loadLabel(pm));
         } catch (PackageManager.NameNotFoundException e) {
             e.printStackTrace();
         }
 
-        TextView mLaunchApp = (TextView) findViewById(R.id.start_the_app_button);
+        View launchApp = findViewById(R.id.start_the_app_button);
 
-        mLaunchApp.setOnClickListener(new View.OnClickListener() {
+        launchApp.setOnClickListener(new View.OnClickListener() {
+            private Intent mStartIntent;
+            private View.OnClickListener setup(Intent si) {
+                mStartIntent = si;
+                return this;
+            }
             @Override
             public void onClick(View v) {
+                Intent originalIntent = ((Intent) mStartIntent.getExtras().get("originalIntent"));
                 // Launch Intent to App Settings
-                mDatabase.addPackageName(component.getPackageName());
-
-                startApplication(mOriginalIntent, mOptions);
+                AppSettingsDatabaseHelper.addPackageName(originalIntent.getComponent().getPackageName());
+                startApplication(mStartIntent);
             }
-        });
+        }.setup(startIntent));
 
-        TextView mTakeMeBackBtn = (TextView) findViewById(R.id.take_me_back_button);
+        View takeMeBackBtn = findViewById(R.id.take_me_back_button);
 
-        mTakeMeBackBtn.setOnClickListener(new View.OnClickListener() {
+        takeMeBackBtn.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 finish();
@@ -186,53 +199,79 @@
         TripleSwitchView mNotificationSwitch = new TripleSwitchView(this, findViewById(R.id.notification_switch), appInfo);
 
 
-        final Pair<PackageInfo, List<String>> permissionInfo = OperationsManager.getValidPermissionListForPackage(pm, component.getPackageName());
+        Pair<PackageInfo, List<String>> permissionInfo = OperationsManager.getValidPermissionListForPackage(pm, component.getPackageName());
 
         Pair<PrivacyImpactCalculator.PRIVACY_LEVEL, Double> privacy = PrivacyImpactCalculator.calculateLevel(permissionInfo.second);
-        mPrivacyLevel = privacy.first;
+        PrivacyImpactCalculator.PRIVACY_LEVEL privacyLevel = privacy.first;
 
-        View mPrivacyImpactGroup = findViewById(R.id.privacy_group);
-        mPrivacyImpactGroup.setBackgroundResource(PrivacyImpactCalculator.getPrivacyBackground(mPrivacyLevel));
-        TextView mPrivacyLevelText = (TextView) findViewById(R.id.privacy_level);
-        mPrivacyLevelText.setText(PrivacyImpactCalculator.getPrivacyName(this, mPrivacyLevel) + (DEBUG ? " -- " + privacy.second : ""));
-        mPrivacyImpactGroup.setOnClickListener(new View.OnClickListener() {
+        View privacyImpactGroup = findViewById(R.id.privacy_group);
+        privacyImpactGroup.setBackgroundResource(PrivacyImpactCalculator.getPrivacyBackground(privacyLevel));
+
+        TextView privacyLevelText = (TextView) findViewById(R.id.privacy_level);
+        privacyLevelText.setText(PrivacyImpactCalculator.getPrivacyName(this, privacyLevel) + (DEBUG ? " -- " + privacy.second : ""));
+
+        privacyImpactGroup.setOnClickListener(new View.OnClickListener() {
+            private Pair<PackageInfo, List<String>> mPermissionInfo; 
+            private PrivacyImpactCalculator.PRIVACY_LEVEL mPrivacyLevel;
+            public View.OnClickListener setup(PrivacyImpactCalculator.PRIVACY_LEVEL lvl, Pair<PackageInfo, List<String>> pi){
+                mPermissionInfo = pi;
+                mPrivacyLevel = lvl;
+                return this;
+            }
             @Override
             public void onClick(View v) {
                 //Toast.makeText(GrantAccessActivity.this, "Priority is " + PrivacyImpactCalculator.getPrivacyName(GrantAccessActivity.this, mPrivacyLevel), Toast.LENGTH_SHORT).show();
                 PrivacyImpactPopupDialog popupDialog = new PrivacyImpactPopupDialog();
                 popupDialog.setPrivacyLevel(mPrivacyLevel);
-                popupDialog.setPackageInfoAndPermissionList(permissionInfo.first, permissionInfo.second);
+                popupDialog.setPackageInfoAndPermissionList(mPermissionInfo.first, mPermissionInfo.second);
                 FragmentManager fm = getSupportFragmentManager();
                 popupDialog.show(fm, mPrivacyLevel.name());
             }
-        });
+        }.setup(privacyLevel, permissionInfo));
 
         CheckBox hidePrivacyImpactCheckbox = (CheckBox) findViewById(R.id.hide_privacy_impact_checkbox);
 
         hidePrivacyImpactCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+            private Context mContext;
+            private CompoundButton.OnCheckedChangeListener setup(Context ctx) {
+                mContext = ctx;
+                return this;
+            }
             @Override
-            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-                SharedPreferences.Editor editor = mDefaultSharedPreferences.edit();
+            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {        
+                SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
+                SharedPreferences.Editor editor = defaultSharedPreferences.edit();
                 editor.putBoolean(HIDE_PRIVACY_IMPACT_PREFERENCE, isChecked);
                 editor.apply();
             }
-        });
+        }.setup(this));
     }
 
-    private void startApplication(Intent originalIntent, Bundle options) {
+    private void startApplication(Intent startIntent) {
+        Bundle extras = startIntent.getExtras();
+        Intent originalIntent = (Intent) extras.get("originalIntent");
+        Bundle originalOptions = (Bundle) extras.get("originalOptions");
+        int originalRequestCode = (int) extras.get("originalRequestCode");
         try {
             originalIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            if (options != null) {
-                startActivityForResult(originalIntent, -1, options);
-                finish();
+            if (originalOptions != null) {
+                startActivityForResult(originalIntent, originalRequestCode, originalOptions);
             } else {
                 // Note we want to go through this call for compatibility with
                 // applications that may have overridden the method.
-                startActivityForResult(originalIntent, -1);
-                finish();
+                startActivityForResult(originalIntent, originalRequestCode);
             }
-        } catch (RuntimeException ren) {
-            Log.e(TAG, "Could not launch application", ren);
+        } catch (RuntimeException e) {
+            Log.e(TAG, "Could not launch application", e);
         }
+        finish();
+    }
+    
+    private static abstract class OnClickListenerInActivity implements View.OnClickListener {
+        protected Activity mActivity;
+        OnClickListenerInActivity(Activity ctx) {
+            mActivity = ctx;
+        }
+        public abstract void onClick (View v);
     }
 }
diff --git a/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/database/AppSettingsDatabaseHelper.java b/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/database/AppSettingsDatabaseHelper.java
index d02c4b0..1b05b8f 100644
--- a/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/database/AppSettingsDatabaseHelper.java
+++ b/packages/FairphonePrivacyImpact/src/com/fairphone/privacyimpact/database/AppSettingsDatabaseHelper.java
@@ -10,13 +10,7 @@
 
     private static final String TAG = AppSettingsDatabaseHelper.class.getName();
 
-    private final Context mContext;
-
-    public AppSettingsDatabaseHelper(Context context) {
-        mContext = context;
-    }
-
-    public boolean isPackageEnable(String packageName){
+    public static boolean isPackageEnable(String packageName){
         boolean result = true;
         try {
             IPrivacyImpactService pis = IPrivacyImpactService.Stub.asInterface(ServiceManager.getService("PrivacyImpact"));
@@ -27,7 +21,7 @@
         return result;
     }
 
-    public void addPackageName(String packageName){
+    public static void addPackageName(String packageName){
         try {
             IPrivacyImpactService pis = IPrivacyImpactService.Stub.asInterface(ServiceManager.getService("PrivacyImpact"));
             pis.disablePackagePrivacy(packageName);