forked from flankerhqd/vendor-android-cves
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
573 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
76 changes: 76 additions & 0 deletions
76
smtshell/app/src/main/java/com/samsung/SMT/lang/smtshell/ConflictActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.samsung.SMT.lang.smtshell; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.RequiresApi; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* We need to keep the minSdkVersion at 22 or lower, so use @RequiresApi to use newer stuff. | ||
* This only needs to support Android 9.0 (API 28) and higher anyway. | ||
*/ | ||
@RequiresApi(api = Build.VERSION_CODES.N) | ||
public class ConflictActivity extends AppCompatActivity { | ||
|
||
private TextView mTextView; | ||
private ListView mListView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_conflict); | ||
mTextView = findViewById(R.id.text); | ||
mListView = findViewById(R.id.list); | ||
if (resolvePackageConflicts()) { | ||
launchMain(); | ||
} | ||
} | ||
|
||
/** | ||
* This will fire when we get a response from an uninstall request. No need to check the | ||
* requestCode or resultCode, since we only care about one result for now. | ||
*/ | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (resolvePackageConflicts()) { | ||
launchMain(); | ||
} | ||
} | ||
|
||
private void launchMain() { | ||
Intent intent = new Intent(this, MainActivity.class); | ||
// prevent annoying UX for user, if they tap back | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||
startActivity(intent); | ||
} | ||
|
||
private boolean resolvePackageConflicts() { | ||
ArrayList<String> pkgs = ConflictUtil.getPackageConflicts(this); | ||
|
||
if (pkgs.size() > 0) { | ||
mTextView.setText(R.string.app_conflict_prompt); | ||
mListView.setAdapter(new ArrayAdapter<>(this, R.layout.pkg_item, pkgs)); | ||
mListView.setOnItemClickListener((parent, view, position, id) -> { | ||
String pkgName = pkgs.get(position); | ||
Intent intent = new Intent(Intent.ACTION_DELETE); | ||
intent.setData(Uri.parse("package:" + pkgName)); | ||
startActivityForResult(intent, 0); | ||
}); | ||
return false; | ||
} else { | ||
mTextView.setText(R.string.no_conflicts); | ||
mListView.setAdapter(null); | ||
return true; | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
smtshell/app/src/main/java/com/samsung/SMT/lang/smtshell/ConflictUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.samsung.SMT.lang.smtshell; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.widget.ArrayAdapter; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* We need to keep the minSdkVersion at 22 or lower, so use @RequiresApi to use newer stuff. | ||
* This only needs to support Android 9.0 (API 28) and higher anyway. | ||
*/ | ||
@RequiresApi(api = Build.VERSION_CODES.N) | ||
public class ConflictUtil { | ||
|
||
public static ArrayList<String> getPackageConflicts(Context context) { | ||
ArrayList<String> pkgs = context.getPackageManager() | ||
.getInstalledPackages(PackageManager.MATCH_ALL) | ||
.stream() | ||
.map(packageInfo -> packageInfo.packageName) | ||
.filter(pkgName -> pkgName.startsWith("com.samsung.SMT.lang")) | ||
.filter(pkgName -> !pkgName.equals(context.getPackageName())) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
return pkgs; | ||
} | ||
|
||
public static boolean hasConflicts(Context context) { | ||
return getPackageConflicts(context).size() > 0; | ||
} | ||
|
||
} |
Oops, something went wrong.