Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[container-gen] Custom Android permissions configuration for native components #606

Merged
merged 3 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
package="com.walmartlabs.ern.container">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
{{#plugins}}
{{#customPermissions}}
<uses-permission android:name="{{{.}}}" />
{{/customPermissions}}
{{/plugins}}
<application>
{{#miniApps}}
<activity android:name="com.walmartlabs.ern.container.miniapps.{{{pascalCaseName}}}Activity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;

public class ElectrodeMiniAppActivity extends Activity implements ElectrodeReactActivityDelegate.BackKeyHandler {
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;

public class ElectrodeMiniAppActivity extends Activity implements ElectrodeReactActivityDelegate.BackKeyHandler, PermissionAwareActivity {

private static final String INITIAL_PROPS = "props";
private ElectrodeReactActivityDelegate mReactActivityDelegate;
private PermissionListener mPermissionListener;

/**
* Method that helps to pass bundle to react native side.
Expand Down Expand Up @@ -111,4 +117,25 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
public void onBackKey() {
finish();
}

@Override
public int checkPermission(String permission, int pid, int uid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be okay to remove this method as it's returning default int value (there is no logic involved)

return PackageManager.PERMISSION_GRANTED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is supposed to return PERMISSION_GRANTED or PERMISSION_DENIED based on if the permission is allowed for a particular pid/uid. Overriding with permission granted may have an inverse effect for the feature ?.

}

@Override
public int checkSelfPermission(String permission) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be okay to remove this method as it's returning default int value (there is no logic involved)

return PackageManager.PERMISSION_GRANTED;
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add @RequiresApi(api = Build.VERSION_CODES.M) to avoid lint warning

public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
mPermissionListener = listener;
ActivityCompat.requestPermissions(this, permissions, requestCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call mReactActivityDelegate. requestPermissions() as the delegate now extends the ReactActivityDelegate.

}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call mReactActivityDelegate. onRequestPermissionsResult() as the delegate now extends the ReactActivityDelegate.

}
}
5 changes: 5 additions & 0 deletions ern-container-gen/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ export async function generatePluginsMustacheViews (
pluginView.customRepos.push(...pluginConfig.android.repositories)
}

pluginView.customPermissions = []
if (pluginConfig.android && pluginConfig.android.permissions) {
pluginView.customPermissions.push(...pluginConfig.android.permissions)
}

if (containerHeader) {
pluginView.containerHeader = containerHeader
}
Expand Down