diff --git a/app/build.gradle b/app/build.gradle index fa0d5e2..13caba6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.google.android.kk" minSdkVersion 15 targetSdkVersion 26 - versionCode 37 - versionName "1.8.3" + versionCode 38 + versionName "2.0.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -66,6 +66,8 @@ dependencies { compile 'com.android.support:recyclerview-v7:26.1.0' compile 'com.google.android.exoplayer:exoplayer:2.6.1' compile 'com.github.javiersantos:AppUpdater:2.6.4' + compile 'eu.chainfire:libsuperuser:1.0.0.+' + } diff --git a/app/src/main/java/com/thekirankumar/youtubeauto/activity/MainPhoneActivity.java b/app/src/main/java/com/thekirankumar/youtubeauto/activity/MainPhoneActivity.java index 8c68ee9..f2fe95c 100644 --- a/app/src/main/java/com/thekirankumar/youtubeauto/activity/MainPhoneActivity.java +++ b/app/src/main/java/com/thekirankumar/youtubeauto/activity/MainPhoneActivity.java @@ -17,6 +17,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_phone_main); } + @Override protected void onResume() { super.onResume(); diff --git a/app/src/main/java/com/thekirankumar/youtubeauto/fragments/WebViewPhoneFragment.java b/app/src/main/java/com/thekirankumar/youtubeauto/fragments/WebViewPhoneFragment.java index 9c37b3d..4cdfdcb 100644 --- a/app/src/main/java/com/thekirankumar/youtubeauto/fragments/WebViewPhoneFragment.java +++ b/app/src/main/java/com/thekirankumar/youtubeauto/fragments/WebViewPhoneFragment.java @@ -9,6 +9,8 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.net.Uri; import android.os.Build; @@ -24,6 +26,7 @@ import android.support.v4.media.session.MediaControllerCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; +import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -42,6 +45,7 @@ import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import com.github.javiersantos.appupdater.AppUpdater; import com.github.javiersantos.appupdater.enums.Display; @@ -64,18 +68,21 @@ import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.net.URLDecoder; +import java.util.HashSet; + +import eu.chainfire.libsuperuser.Shell; import static com.thekirankumar.youtubeauto.fragments.WebViewCarFragment.HOME_URL; import static com.thekirankumar.youtubeauto.fragments.WebViewCarFragment.YOUTUBE_HOME_URL_BASE; public class WebViewPhoneFragment extends CarFragment implements BookmarksClickCallback, ExoPlayerFragment.OnFragmentInteractionListener { + public static final String GITHUB_REPO_USERNAME = "thekirankumar"; + public static final String GITHUB_REPO_URL = "youtube-android-auto"; private static final int READ_STORAGE_PERMISSION_REQUEST_CODE = 10; private static final String BOOKMARKS_FRAGMENT_TAG = "bookmarks"; private static final String PLAYER_FRAGMENT_TAG = "player"; private static final String PREFS = "phone_prefs"; - public static final String GITHUB_REPO_USERNAME = "thekirankumar"; - public static final String GITHUB_REPO_URL = "youtube-android-auto"; private final String TAG = "WebViewCarFragment"; private VideoWebView webView; private EditText editText; @@ -163,10 +170,52 @@ public boolean onOptionsItemSelected(MenuItem item) { showBookmarksScreen(); } else if (item.getItemId() == R.id.settings) { startActivity(new Intent(getContext(), SettingsPhoneActivity.class)); + } else if (item.getItemId() == R.id.unlock) { + unlock(); } return super.onOptionsItemSelected(item); } + private void unlock() { + if (Shell.SU.available()) { + Shell.SU.run("pm disable --user 0 com.google.android.gms/.phenotype.service.sync.PhenotypeConfigurator"); + Shell.SU.run("pm disable --user 0 com.google.android.gms/.phenotype.service.PhenotypeService"); + Shell.SU.run("chmod 777 /data/data/com.google.android.gms/databases/phenotype.db*"); + try { + SQLiteDatabase sql = SQLiteDatabase.openDatabase("/data/data/com.google.android.gms/databases/phenotype.db", null, 0); + if (sql != null) { + Cursor cursor = sql.rawQuery("SELECT stringVal FROM Flags WHERE packageName=? AND name=?;", new String[]{"com.google.android.gms.car", "app_white_list"}); + HashSet packageNames = new HashSet<>(); + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + String stringVal = cursor.getString(cursor.getColumnIndex("stringVal")); + if (stringVal != null) { + packageNames.add(stringVal); + } + } + } + cursor.close(); + packageNames.add(getActivity().getApplicationContext().getPackageName()); //add myself + sql.execSQL("DELETE FROM Flags WHERE packageName=\"com.google.android.gms.car\" AND name=\"app_white_list\";"); + String joinedPackageNames = TextUtils.join(",", packageNames); + sql.execSQL("INSERT INTO Flags (packageName, version, flagType, partitionId, user, name, stringVal, committed) VALUES (\"com.google.android.gms.car\", 209, 0, 0, \"\", \"app_white_list\", \"" + joinedPackageNames + "\", 1);"); + sql.execSQL("INSERT INTO Flags (packageName, version, flagType, partitionId, user, name, stringVal, committed) VALUES (\"com.google.android.gms.car\", 224, 0, 0, \"\", \"app_white_list\", \"" + joinedPackageNames + "\", 1);"); + sql.close(); + Toast.makeText(getActivity(), "Successfully unlocked. Reboot phone and connect to Android Auto", Toast.LENGTH_LONG).show(); + } + } catch (Exception e) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("sql exception : "); + stringBuilder.append(e.toString()); + Toast.makeText(getActivity(), "Error in executing commands : " + stringBuilder.toString(), Toast.LENGTH_LONG).show(); + } + Shell.SU.run("chmod 660 /data/data/com.google.android.gms/databases/phenotype.db*"); + return; + } + Toast.makeText(getActivity(), "Root not available, install SuperSU and perform root first.", Toast.LENGTH_LONG).show(); + } + + @Override public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -392,7 +441,7 @@ private void hideBookmarksScreen() { } private void showBookmarksScreen() { - if (isAdded() && getView()!=null) { + if (isAdded() && getView() != null) { getView().findViewById(R.id.full_screen_view).setVisibility(View.VISIBLE); FragmentManager childFragmentManager = getChildFragmentManager(); BookmarksFragment bookmarksFragment = (BookmarksFragment) childFragmentManager.findFragmentByTag(BOOKMARKS_FRAGMENT_TAG); @@ -470,16 +519,16 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request public boolean shouldOverrideUrlLoading(WebView view, final String url) { editText.setText(url); if (url.startsWith("file:///") && !url.endsWith("/")) { - view.post(new Runnable() { - @Override - public void run() { - try { - showNativePlayer(URLDecoder.decode(url, "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + view.post(new Runnable() { + @Override + public void run() { + try { + showNativePlayer(URLDecoder.decode(url, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); } - }); + } + }); return true; } else if (url.startsWith("intent://")) { try { diff --git a/app/src/main/res/menu/phone_menu.xml b/app/src/main/res/menu/phone_menu.xml index 3511aff..1e6c963 100644 --- a/app/src/main/res/menu/phone_menu.xml +++ b/app/src/main/res/menu/phone_menu.xml @@ -26,4 +26,9 @@ android:id="@+id/settings" android:title="@string/settings" app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74ca7af..9ed11b6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,7 @@ Add current site Version Settings + Unlock [Root] Car settings Disable notifications Disable head-up notifications in Android Auto