Skip to content

Commit

Permalink
unlocker added (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekirankumar authored Jun 21, 2018
1 parent f0ca595 commit cd96579
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 14 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.+'

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_phone_main);
}


@Override
protected void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/phone_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="never" />
<item
android:id="@+id/unlock"
android:title="@string/unlock"
app:showAsAction="never" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="add_bookmark">Add current site</string>
<string name="version">Version </string>
<string name="settings">Settings</string>
<string name="unlock">Unlock [Root]</string>
<string name="settings_car_category">Car settings</string>
<string name="settings_car_disable_notifications_title">Disable notifications</string>
<string name="settings_car_disable_notifications_summary">Disable head-up notifications in Android Auto</string>
Expand Down

0 comments on commit cd96579

Please sign in to comment.