Revert "Target SDK level 27 in AppRTCMobile."
This reverts commit af4f1b41277ebdf0d7386cbd2903abc709cbc183. Reason for revert: Causes timeouts with loopback tests. Reverting and investigating. Original change's description: > Target SDK level 27 in AppRTCMobile. > > Implements the dynamic permission model required by the newer SDK and > changes the theme. > > Bug: webrtc:8803 > Change-Id: I3ea23a25b27f196fcffd018c7cdd2ff6255b62d9 > Reviewed-on: https://webrtc-review.googlesource.com/44400 > Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> > Reviewed-by: Anders Carlsson <andersc@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#21788} TBR=sakal@webrtc.org,andersc@webrtc.org Change-Id: I4074c48fc7c7466765793244a5a7f60029bc7937 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:8803 Reviewed-on: https://webrtc-review.googlesource.com/45980 Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21797}
This commit is contained in:
committed by
Commit Bot
parent
2036da9cd8
commit
f61b3ba65e
@ -10,17 +10,12 @@
|
||||
|
||||
package org.appspot.apprtc;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
@ -49,7 +44,6 @@ import org.json.JSONException;
|
||||
public class ConnectActivity extends Activity {
|
||||
private static final String TAG = "ConnectActivity";
|
||||
private static final int CONNECTION_REQUEST = 1;
|
||||
private static final int PERMISSION_REQUEST = 2;
|
||||
private static final int REMOVE_FAVORITE_INDEX = 0;
|
||||
private static boolean commandLineRun = false;
|
||||
|
||||
@ -110,7 +104,16 @@ public class ConnectActivity extends Activity {
|
||||
addFavoriteButton = findViewById(R.id.add_favorite_button);
|
||||
addFavoriteButton.setOnClickListener(addFavoriteListener);
|
||||
|
||||
requestPermissions();
|
||||
// If an implicit VIEW intent is launching the app, go directly to that URL.
|
||||
final Intent intent = getIntent();
|
||||
if ("android.intent.action.VIEW".equals(intent.getAction()) && !commandLineRun) {
|
||||
boolean loopback = intent.getBooleanExtra(CallActivity.EXTRA_LOOPBACK, false);
|
||||
int runTimeMs = intent.getIntExtra(CallActivity.EXTRA_RUNTIME, 0);
|
||||
boolean useValuesFromIntent =
|
||||
intent.getBooleanExtra(CallActivity.EXTRA_USE_VALUES_FROM_INTENT, false);
|
||||
String room = sharedPref.getString(keyprefRoom, "");
|
||||
connectToRoom(room, true, loopback, useValuesFromIntent, runTimeMs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -207,101 +210,6 @@ public class ConnectActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(
|
||||
int requestCode, String[] permissions, int[] grantResults) {
|
||||
if (requestCode == PERMISSION_REQUEST) {
|
||||
String[] missingPermissions = getMissingPermissions();
|
||||
if (missingPermissions.length != 0) {
|
||||
// User didn't grant all the permissions. Warn that the application might not work
|
||||
// correctly.
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.missing_permissions_try_again)
|
||||
.setPositiveButton(R.string.yes,
|
||||
(dialog, id) -> {
|
||||
// User wants to try giving the permissions again.
|
||||
dialog.cancel();
|
||||
requestPermissions();
|
||||
})
|
||||
.setNegativeButton(R.string.no,
|
||||
(dialog, id) -> {
|
||||
// User doesn't want to give the permissions.
|
||||
dialog.cancel();
|
||||
onPermissionsGranted();
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
// All permissions granted.
|
||||
onPermissionsGranted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onPermissionsGranted() {
|
||||
// If an implicit VIEW intent is launching the app, go directly to that URL.
|
||||
final Intent intent = getIntent();
|
||||
if ("android.intent.action.VIEW".equals(intent.getAction()) && !commandLineRun) {
|
||||
boolean loopback = intent.getBooleanExtra(CallActivity.EXTRA_LOOPBACK, false);
|
||||
int runTimeMs = intent.getIntExtra(CallActivity.EXTRA_RUNTIME, 0);
|
||||
boolean useValuesFromIntent =
|
||||
intent.getBooleanExtra(CallActivity.EXTRA_USE_VALUES_FROM_INTENT, false);
|
||||
String room = sharedPref.getString(keyprefRoom, "");
|
||||
connectToRoom(room, true, loopback, useValuesFromIntent, runTimeMs);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private void requestPermissions() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
// Dynamic permissions are not required before Android M.
|
||||
onPermissionsGranted();
|
||||
return;
|
||||
}
|
||||
|
||||
String[] missingPermissions = getMissingPermissions();
|
||||
if (missingPermissions.length != 0) {
|
||||
requestPermissions(missingPermissions, PERMISSION_REQUEST);
|
||||
} else {
|
||||
onPermissionsGranted();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private String[] getMissingPermissions() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
PackageInfo info;
|
||||
try {
|
||||
info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.w(TAG, "Failed to retrieve permissions.");
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
if (info.requestedPermissions == null) {
|
||||
Log.w(TAG, "No requested permissions.");
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
ArrayList<String> missingPermissions = new ArrayList<>();
|
||||
for (int i = 0; i < info.requestedPermissions.length; i++) {
|
||||
if (Manifest.permission.CAPTURE_VIDEO_OUTPUT.equals(info.requestedPermissions[i])) {
|
||||
// Screen recording permission has to be asked every time a session is started. (See
|
||||
// CallActivity#startScreenCapture.)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((info.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
|
||||
missingPermissions.add(info.requestedPermissions[i]);
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Missing permissions: " + missingPermissions);
|
||||
|
||||
return missingPermissions.toArray(new String[missingPermissions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from the shared preference or from the intent, if it does not
|
||||
* exist the default is used.
|
||||
|
||||
Reference in New Issue
Block a user