Skip to content

Commit

Permalink
Add permission check for M and do not die when enabling backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Mar 4, 2016
1 parent 724063f commit 859fbd4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import android.os.IBinder;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.microg.nlp.Preferences;
import org.microg.nlp.R;
Expand Down Expand Up @@ -199,27 +201,33 @@ public void onClick(View v) {
}

protected void enableBackend(BackendInfo backendInfo) {
if (backendInfo.getMeta(METADATA_BACKEND_INIT_ACTIVITY) != null) {
getContext().startActivity(createExternalIntent(backendInfo, METADATA_BACKEND_INIT_ACTIVITY));
} else {
Intent intent = buildBackendIntent();
intent.setPackage(backendInfo.serviceInfo.packageName);
intent.setClassName(backendInfo.serviceInfo.packageName, backendInfo.serviceInfo.name);
getContext().bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Intent i = getBackendInitIntent(service);
if (i != null) {
getContext().startActivity(i);
try {
if (backendInfo.getMeta(METADATA_BACKEND_INIT_ACTIVITY) != null) {
getContext().startActivity(createExternalIntent(backendInfo, METADATA_BACKEND_INIT_ACTIVITY));
} else {
Intent intent = buildBackendIntent();
intent.setPackage(backendInfo.serviceInfo.packageName);
intent.setClassName(backendInfo.serviceInfo.packageName, backendInfo.serviceInfo.name);
getContext().bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Intent i = getBackendInitIntent(service);
if (i != null) {
getContext().startActivity(i);
}
getContext().unbindService(this);
}
getContext().unbindService(this);
}

@Override
public void onServiceDisconnected(ComponentName name) {
@Override
public void onServiceDisconnected(ComponentName name) {

}
}, BIND_AUTO_CREATE);
}
}, BIND_AUTO_CREATE);
}
} catch (Exception e) {
backendInfo.enabled = false;
Toast.makeText(getContext(), "Error initializing backend", Toast.LENGTH_SHORT).show();
resetAdapter();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@
import org.microg.nlp.R;
import org.microg.tools.selfcheck.NlpOsCompatChecks;
import org.microg.tools.selfcheck.NlpStatusChecks;
import org.microg.tools.selfcheck.PermissionCheckGroup;
import org.microg.tools.selfcheck.SelfCheckGroup;
import org.microg.tools.ui.AbstractAboutFragment;
import org.microg.tools.ui.AbstractSelfCheckFragment;

import java.util.List;

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1;

public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -94,6 +99,9 @@ public static class MySelfCheckFragment extends AbstractSelfCheckFragment {

@Override
protected void prepareSelfCheckList(List<SelfCheckGroup> checks) {
if (SDK_INT > LOLLIPOP_MR1) {
checks.add(new PermissionCheckGroup(ACCESS_COARSE_LOCATION));
}
checks.add(new NlpOsCompatChecks());
checks.add(new NlpStatusChecks());
}
Expand Down

1 comment on commit 859fbd4

@xuefer
Copy link

@xuefer xuefer commented on 859fbd4 Mar 4, 2016

Choose a reason for hiding this comment

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

Thanks, keep on
because there's no way to grant permission in app's permission setting when UnifiedNlp is used as system NLP. see #68

Please sign in to comment.