SetupWizard bringup for Android 9 PIE

* Updated SDK to 28
* Updated accessibility
* Pass proper value to wifi back text
* Explicitly include java support packages
* Remove tests

Issue: FP2P-459
Change-Id: I748f00943288f8776ed071647a2413ece676636c
diff --git a/Android.mk b/Android.mk
index 915e1cf..e3b1ec4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -10,11 +10,19 @@
 LOCAL_PRIVILEGED_MODULE := true
 LOCAL_OVERRIDES_PACKAGES := Provision
 
+LOCAL_PRIVATE_PLATFORM_APIS := true
+
 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
 
-LOCAL_STATIC_JAVA_LIBRARIES := \
+LOCAL_STATIC_ANDROID_LIBRARIES := \
     android-support-v4 \
+    android-support-v7-appcompat \
+    android-support-v7-preference \
+    android-support-v7-recyclerview \
     android-support-v13 \
+    android-support-v14-preference
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
     libphonenumber
 
 LOCAL_JAVA_LIBRARIES := \
@@ -22,7 +30,10 @@
 
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
 
-include frameworks/opt/setupwizard/library/common.mk
+LOCAL_USE_AAPT2 := true
+
+include frameworks/opt/setupwizard/navigationbar/common.mk
+include frameworks/opt/setupwizard/library/common-gingerbread.mk
 
 include $(BUILD_PACKAGE)
 
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ccaa995..74ed3df 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -20,9 +20,9 @@
           android:sharedUserId="android.uid.system">
 
     <uses-sdk
-        android:minSdkVersion="25"
-        android:targetSdkVersion="25"
-        android:maxSdkVersion="25" />
+        android:minSdkVersion="28"
+        android:targetSdkVersion="28"
+        android:maxSdkVersion="28" />
 
     <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
     <uses-permission android:name="android.permission.STATUS_BAR" />
diff --git a/src/com/fairphone/setupwizard/SetupWizardApp.java b/src/com/fairphone/setupwizard/SetupWizardApp.java
index eaea742..a1e8fe4 100644
--- a/src/com/fairphone/setupwizard/SetupWizardApp.java
+++ b/src/com/fairphone/setupwizard/SetupWizardApp.java
@@ -34,7 +34,7 @@
 
     public static final String ACTION_FINISHED = "com.fairphone.fairphone.SETUP_FINISHED";
 
-    public static final String ACTION_SETUP_WIFI = "com.android.net.wifi.SETUP_WIFI_NETWORK";
+    public static final String ACTION_SETUP_WIFI = "android.net.wifi.PICK_WIFI_NETWORK";
 
     public static final String ACTION_SETUP_FINGERPRINT = "android.settings.FINGERPRINT_SETUP";
     public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN";
@@ -52,6 +52,8 @@
     public static final String EXTRA_FRAGMENT = "fragment";
     public static final String EXTRA_ACTION_ID = "actionId";
     public static final String EXTRA_SUPRESS_D2D_SETUP = "suppress_device_to_device_setup";
+    public static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
+    public static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
 
     public static final String KEY_DETECT_CAPTIVE_PORTAL = "captive_portal_detection_enabled";
 
diff --git a/src/com/fairphone/setupwizard/setup/WifiSetupPage.java b/src/com/fairphone/setupwizard/setup/WifiSetupPage.java
index a4bfbcb..4c03945 100644
--- a/src/com/fairphone/setupwizard/setup/WifiSetupPage.java
+++ b/src/com/fairphone/setupwizard/setup/WifiSetupPage.java
@@ -230,11 +230,8 @@
         if (SetupWizardUtils.hasLeanback(mContext)) {
             intent.setComponent(SetupWizardUtils.mTvwifisettingsActivity);
         }
-        intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
-        intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
-        intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
-        intent.putExtra(SetupWizardApp.EXTRA_THEME, SetupWizardApp.EXTRA_MATERIAL_LIGHT);
-        intent.putExtra(SetupWizardApp.EXTRA_AUTO_FINISH, false);
+        intent.putExtra(SetupWizardApp.EXTRA_PREFS_SHOW_BUTTON_BAR, true);
+        intent.putExtra(SetupWizardApp.EXTRA_PREFS_SET_BACK_TEXT , (String) null);
         ActivityOptions options =
                 ActivityOptions.makeCustomAnimation(mContext,
                         android.R.anim.fade_in,
diff --git a/src/com/fairphone/setupwizard/util/EnableAccessibilityController.java b/src/com/fairphone/setupwizard/util/EnableAccessibilityController.java
index bec17d7..a4f6589 100644
--- a/src/com/fairphone/setupwizard/util/EnableAccessibilityController.java
+++ b/src/com/fairphone/setupwizard/util/EnableAccessibilityController.java
@@ -58,18 +58,11 @@
         public void handleMessage(Message message) {
             switch (message.what) {
                 case MESSAGE_SPEAK_WARNING: {
-                    String text = mContext.getString(R.string.continue_to_enable_accessibility);
-                    mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
                 } break;
                 case MESSAGE_SPEAK_ENABLE_CANCELED: {
-                    String text = mContext.getString(R.string.enable_accessibility_canceled);
-                    mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
                 } break;
                 case MESSAGE_ENABLE_ACCESSIBILITY: {
                     enableAccessibility();
-                    mTone.play();
-                    mTts.speak(mContext.getString(R.string.accessibility_enabled),
-                            TextToSpeech.QUEUE_FLUSH, null);
                 } break;
             }
         }
@@ -277,9 +270,6 @@
                 Settings.Secure.putIntForUser(resolver, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
                         1, userId);
             }
-            // Enable accessibility script injection (AndroidVox) for web content.
-            Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION,
-                    1, userId);
             // Turn on accessibility mode last.
             Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED,
                     1, userId);
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 30618ea..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_PRIVILEGED_MODULE := true
-
-LOCAL_STATIC_JAVA_LIBRARIES := \
-    org.cyanogenmod.platform.sdk
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := CyanogenSetupWizardTests
-LOCAL_CERTIFICATE := platform
-
-include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
deleted file mode 100644
index ac59a6f..0000000
--- a/tests/AndroidManifest.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2013 The CyanogenMod Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="com.cyanogenmod.setupwizard.tests">
-    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
-    <uses-permission android:name="android.permission.STATUS_BAR"/>
-    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
-    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
-    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> >
-    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
-    <uses-permission android:name="android.permission.INTERNET"/>
-    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
-    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
-    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
-    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
-    <uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
-    <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
-    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
-    <uses-permission android:name="cyanogenmod.permission.WRITE_SETTINGS"/>
-    <uses-permission android:name="cyanogenmod.permission.WRITE_SECURE_SETTINGS"/>
-
-    <application android:icon="@drawable/icon">
-        <uses-library android:name="android.test.runner" />
-        <activity android:name="com.cyanogenmod.setupwizard.tests.ManualTestActivity"
-                  android:label="@string/app_test"
-                  android:theme="@android:style/Theme.Material.NoActionBar"
-                  android:launchMode="singleTask">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-    </application>
-
-    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21" />
-
-    <instrumentation android:name="android.test.InstrumentationTestRunner"
-                     android:targetPackage="com.cyanogenmod.setupwizard"
-                     android:label="Tests for CMSetupWizard."/>
-
-</manifest>
diff --git a/tests/res/drawable/icon.png b/tests/res/drawable/icon.png
deleted file mode 100644
index 0a2f2e4..0000000
--- a/tests/res/drawable/icon.png
+++ /dev/null
Binary files differ
diff --git a/tests/res/layout/cmaccount_test.xml b/tests/res/layout/cmaccount_test.xml
deleted file mode 100644
index 488f691..0000000
--- a/tests/res/layout/cmaccount_test.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2013 The CyanogenMod Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-            android:layout_height="match_parent"
-            android:layout_width="match_parent">
-    <LinearLayout android:layout_height="match_parent"
-                  android:layout_width="match_parent"
-                  android:orientation="vertical">
-
-        <Button android:id="@+id/enable_setup"
-                android:layout_height="wrap_content"
-                android:layout_width="match_parent"
-                android:text="@string/enable_setup"/>
-
-        <Button android:id="@+id/enable_google_setup"
-                android:layout_height="wrap_content"
-                android:layout_width="match_parent"
-                android:text="@string/enable_google_setup"/>
-
-        <Button android:id="@+id/setup_complete_flag"
-                android:layout_height="wrap_content"
-                android:layout_width="match_parent"
-                android:text="@string/user_setup_complete"/>
-
-    </LinearLayout>
-</ScrollView>
diff --git a/tests/res/values/strings.xml b/tests/res/values/strings.xml
deleted file mode 100644
index 0bba372..0000000
--- a/tests/res/values/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2013 The CyanogenMod Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<resources>
-    <string name="app_test">SetupWizard Test</string>
-    <string name="enable_setup">Enable Setup Wizard</string>
-    <string name="enable_google_setup">Enable Google Setup Wizard</string>
-    <string name="user_setup_complete">Set SetupWizard complete</string>
-</resources>
diff --git a/tests/src/com/cyanogenmod/account/tests/ManualTestActivity.java b/tests/src/com/cyanogenmod/account/tests/ManualTestActivity.java
deleted file mode 100644
index b9c2312..0000000
--- a/tests/src/com/cyanogenmod/account/tests/ManualTestActivity.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2013 The CyanogenMod Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.cyanogenmod.setupwizard.tests;
-
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ComponentInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Bundle;
-import android.provider.Settings;
-import android.view.View;
-import android.widget.Toast;
-
-import cyanogenmod.providers.CMSettings;
-
-public class ManualTestActivity extends Activity {
-
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.cmaccount_test);
-
-        findViewById(R.id.enable_setup).setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                enableSetup();
-            }
-        });
-        findViewById(R.id.enable_google_setup).setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                enableGoogleSetup();
-            }
-        });
-        findViewById(R.id.setup_complete_flag).setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                setSetupComplete();
-            }
-        });
-    }
-
-    private void enableSetup() {
-        Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
-        Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 0);
-        CMSettings.Secure.putInt(getContentResolver(),
-                CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, 0);
-        Intent intent = new Intent("android.intent.action.MAIN");
-        intent.addCategory("android.intent.category.HOME");
-        final PackageManager pm = getPackageManager();
-        ComponentName componentName = new ComponentName("com.cyanogenmod.setupwizard",
-                "com.cyanogenmod.setupwizard.ui.SetupWizardActivity");
-        pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
-                PackageManager.DONT_KILL_APP);
-        componentName = new ComponentName("com.cyanogenmod.setupwizard",
-                "com.cyanogenmod.setupwizard.setup.FinishSetupReceiver");
-        pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
-                PackageManager.DONT_KILL_APP);
-        pm.clearApplicationUserData("com.cyanogenmod.setupwizard", null);
-        ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
-        am.killBackgroundProcesses("com.cyanogenmod.setupwizard");
-        try {
-            PackageInfo packageInfo = getPackageManager()
-                    .getPackageInfo("com.google.android.setupwizard",
-                            PackageManager.GET_ACTIVITIES |
-                                    PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES);
-            enableComponentArray(packageInfo.activities);
-            enableComponentArray(packageInfo.services);
-            enableComponentArray(packageInfo.receivers);
-            pm.clearApplicationUserData("com.google.android.setupwizard", null);
-        } catch (Exception e) {
-            Toast.makeText(this, "GMS not installed", Toast.LENGTH_SHORT).show();
-            e.printStackTrace();
-        }
-        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
-        startActivity(intent);
-        finish();
-    }
-
-    private void enableGoogleSetup() {
-        try {
-            Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
-            Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 0);
-            Intent intent = new Intent("android.intent.action.MAIN");
-            intent.addCategory("android.intent.category.HOME");
-            final PackageManager pm = getPackageManager();
-            PackageInfo packageInfo = this.getPackageManager()
-                    .getPackageInfo("com.google.android.setupwizard",
-                            PackageManager.GET_ACTIVITIES |
-                                    PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES);
-            enableComponentArray(packageInfo.activities);
-            enableComponentArray(packageInfo.services);
-            enableComponentArray(packageInfo.receivers);
-            pm.clearApplicationUserData("com.google.android.setupwizard", null);
-            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
-            startActivity(intent);
-            finish();
-        } catch (Exception e) {
-            Toast.makeText(this, "GMS not installed", Toast.LENGTH_SHORT).show();
-            e.printStackTrace();
-        }
-    }
-
-    private void setSetupComplete() {
-        Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
-        CMSettings.Secure.putInt(getContentResolver(),
-                CMSettings.Secure.CM_SETUP_WIZARD_COMPLETED, 1);
-        Intent intent = new Intent("android.intent.action.MAIN");
-        intent.addCategory("android.intent.category.HOME");
-        final PackageManager pm = getPackageManager();
-        ComponentName componentName = new ComponentName("com.cyanogenmod.setupwizard",
-                "com.cyanogenmod.setupwizard.ui.SetupWizardActivity");
-        pm.setComponentEnabledSetting(componentName,
-                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
-        ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
-        am.killBackgroundProcesses("com.cyanogenmod.setupwizard");
-        try {
-            PackageInfo packageInfo = this.getPackageManager()
-                    .getPackageInfo("com.google.android.setupwizard",
-                            PackageManager.GET_ACTIVITIES |
-                                    PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES);
-            enableComponentArray(packageInfo.activities);
-            enableComponentArray(packageInfo.services);
-            enableComponentArray(packageInfo.receivers);
-            pm.clearApplicationUserData("com.google.android.setupwizard", null);
-        } catch (Exception e) {
-            Toast.makeText(this, "GMS not installed", Toast.LENGTH_SHORT).show();
-            e.printStackTrace();
-        }
-        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
-        startActivity(intent);
-        finish();
-    }
-
-    private void enableComponentArray(ComponentInfo[] components) {
-        if(components != null) {
-            ComponentInfo[] componentInfos = components;
-            for(int i = 0; i < componentInfos.length; i++) {
-                enableComponent(componentInfos[i].packageName, componentInfos[i].name);
-            }
-        }
-    }
-
-    private void enableComponent(String packageName, String name) {
-        enableComponent(new ComponentName(packageName, name));
-    }
-
-    private void enableComponent(ComponentName component) {
-        getPackageManager().setComponentEnabledSetting(component,
-                PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 1);
-    }
-
-}
\ No newline at end of file