Skip to content

Commit 44a1b40

Browse files
authored
Merge pull request #617 from NativeScript/pete/fix-error-activity-permissions
Fix error activity permissions on devices running on Android 23+
2 parents a8e9b07 + c992342 commit 44a1b40

File tree

12 files changed

+943
-786
lines changed

12 files changed

+943
-786
lines changed

build-artifacts/project-template-gradle/src/debug/java/com/tns/ErrorReport.java

Lines changed: 356 additions & 328 deletions
Large diffs are not rendered by default.

build-artifacts/project-template-gradle/src/debug/java/com/tns/ErrorReportActivity.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import android.os.Bundle;
44
import android.support.annotation.NonNull;
55
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.Toast;
7+
8+
import java.lang.reflect.Method;
9+
10+
import static com.tns.ErrorReport.isCheckingForPermissions;
11+
import static com.tns.ErrorReport.resetCheckingForPermissions;
612

713
public class ErrorReportActivity extends AppCompatActivity {
814
public void onCreate(Bundle savedInstanceState) {
@@ -14,14 +20,25 @@ public void onCreate(Bundle savedInstanceState) {
1420
}
1521

1622
@Override
17-
protected void onPause() {
18-
// the moment the error activity is not in the foreground we want to kill the process
19-
super.onPause();
20-
ErrorReport.killProcess(this);
23+
protected void onUserLeaveHint() {
24+
super.onUserLeaveHint();
25+
26+
if(!isCheckingForPermissions()) {
27+
ErrorReport.killProcess(this);
28+
}
2129
}
2230

2331
// @Override
2432
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
25-
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
33+
try {
34+
Method onRequestPermissionsResultMethod = AppCompatActivity.class.getMethod("onRequestPermissionsResult", int.class, permissions.getClass(), grantResults.getClass());
35+
onRequestPermissionsResultMethod.invoke(new AppCompatActivity() /* never do this */, requestCode, permissions, grantResults);
36+
37+
resetCheckingForPermissions();
38+
} catch (Exception e) {
39+
e.printStackTrace();
40+
Toast.makeText(this, "Couldn't resolve permissions", Toast.LENGTH_LONG).show();
41+
resetCheckingForPermissions();
42+
}
2643
}
2744
}

build-artifacts/project-template-gradle/src/debug/res/layout/error_activity.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,30 @@
1212
android:layout_width="match_parent"
1313
android:layout_height="wrap_content"
1414
android:minHeight="?attr/actionBarSize"
15-
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
16-
17-
<android.support.design.widget.TabLayout
18-
android:id="@+id/tabLayout"
19-
android:layout_width="match_parent"
20-
android:layout_height="wrap_content"
21-
android:background="?attr/colorPrimary"
22-
android:minHeight="?attr/actionBarSize"/>
15+
app:popupTheme="?android:attr/statusBarColor"/>
2316

2417
<android.support.v4.view.ViewPager
2518
android:id="@+id/pager"
2619
android:layout_width="match_parent"
2720
android:layout_height="fill_parent"
28-
android:layout_below="@+id/toolbar">
21+
android:layout_below="@+id/toolbar"
22+
android:scrollbarAlwaysDrawVerticalTrack="false">
2923

3024
</android.support.v4.view.ViewPager>
25+
26+
<android.support.design.widget.TabLayout
27+
android:id="@+id/tabLayout"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:background="?attr/colorPrimary"
31+
android:minHeight="?attr/actionBarSize"
32+
app:tabIndicatorColor="@color/nativescript_blue"
33+
app:tabBackground="?android:attr/statusBarColor"
34+
android:layout_alignParentTop="true"
35+
android:layout_alignParentStart="true"
36+
android:scrollbarStyle="insideOverlay"
37+
android:scrollbars="vertical"
38+
tools:tabBackground="@android:color/darker_gray"
39+
android:scrollbarAlwaysDrawVerticalTrack="false"
40+
/>
3141
</RelativeLayout>

build-artifacts/project-template-gradle/src/debug/res/layout/exception_tab.xml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent"
5-
android:orientation="vertical">
6+
android:orientation="vertical"
7+
android:paddingBottom="10dp"
8+
android:paddingLeft="16dp"
9+
android:paddingRight="16dp"
10+
android:paddingTop="10dp">
11+
12+
<Button
13+
android:id="@+id/btnCopyException"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:layout_alignParentBottom="true"
17+
android:layout_centerHorizontal="true"
18+
android:background="@color/nativescript_blue"
19+
android:paddingLeft="20dp"
20+
android:paddingRight="20dp"
21+
android:text="Copy to clipboard"
22+
android:textAlignment="textStart"
23+
android:textColor="@android:color/white"
24+
tools:layout_width="match_parent"/>
625

726
<LinearLayout
827
android:id="@+id/linearLayout"
928
android:layout_width="match_parent"
1029
android:layout_height="wrap_content"
30+
android:layout_above="@+id/btnCopyException"
31+
android:layout_alignParentStart="true"
32+
android:layout_alignParentTop="true"
1133
android:orientation="vertical"
34+
android:paddingBottom="10dp"
1235
android:weightSum="100">
1336

14-
<LinearLayout
15-
android:layout_width="fill_parent"
16-
android:layout_height="0dp"
17-
android:layout_weight="80">
18-
19-
<TextView
20-
android:id="@+id/txtErrorMsg"
21-
android:layout_width="match_parent"
22-
android:layout_height="match_parent"
23-
android:layout_centerInParent="true"
24-
android:text=""
25-
android:textAppearance="?android:attr/textAppearanceSmall" />
26-
</LinearLayout>
27-
28-
<LinearLayout
37+
<TextView
38+
android:id="@+id/txtErrorMsg"
2939
android:layout_width="match_parent"
30-
android:layout_height="0dp"
31-
android:layout_weight="20">
40+
android:layout_height="wrap_content"
41+
android:text=""
42+
android:textAppearance="?android:attr/textAppearanceSmall"
43+
android:paddingLeft="2dp"
44+
android:paddingRight="2dp"
45+
android:scrollbars="vertical"
46+
android:scrollbarStyle="outsideOverlay"
47+
android:scrollbarAlwaysDrawVerticalTrack="true"/>
3248

33-
<Button
34-
android:id="@+id/btnCopyException"
35-
android:layout_width="match_parent"
36-
android:layout_height="match_parent"
37-
android:layout_alignParentBottom="true"
38-
android:text="Copy to clipboard" />
39-
</LinearLayout>
4049
</LinearLayout>
4150

4251

build-artifacts/project-template-gradle/src/debug/res/layout/logcat_tab.xml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent"
5-
android:orientation="vertical">
6+
android:orientation="vertical"
7+
android:paddingBottom="10dp"
8+
android:paddingLeft="16dp"
9+
android:paddingRight="16dp"
10+
android:paddingTop="10dp">
11+
12+
<Button
13+
android:id="@+id/btnCopyLogcat"
14+
android:layout_height="wrap_content"
15+
android:text="Copy to sdcard"
16+
android:layout_width="match_parent"
17+
android:background="@color/nativescript_blue"
18+
android:textColor="@android:color/white"
19+
android:textAlignment="textStart"
20+
android:paddingLeft="20dp"
21+
android:paddingRight="20dp"
22+
android:layout_alignParentBottom="true"
23+
android:layout_centerHorizontal="true"
24+
tools:layout_width="match_parent"/>
625

726
<LinearLayout
827
android:id="@+id/logcatLinearLayout"
928
android:layout_width="match_parent"
1029
android:layout_height="wrap_content"
1130
android:orientation="vertical"
12-
android:weightSum="100">
13-
14-
<LinearLayout
15-
android:layout_width="match_parent"
16-
android:layout_height="0dp"
17-
android:layout_weight="80">
31+
android:weightSum="100"
32+
android:layout_alignParentTop="true"
33+
android:layout_alignParentStart="true"
34+
android:layout_above="@+id/btnCopyLogcat"
35+
android:paddingBottom="10dp">
1836

19-
<TextView
20-
android:id="@+id/logcatMsg"
21-
android:layout_width="match_parent"
22-
android:layout_height="match_parent"
23-
android:layout_centerInParent="true"
24-
android:text=""
25-
android:textAppearance="?android:attr/textAppearanceSmall" />
26-
</LinearLayout>
27-
28-
<LinearLayout
37+
<TextView
38+
android:id="@+id/logcatMsg"
2939
android:layout_width="match_parent"
30-
android:layout_height="0dp"
31-
android:layout_weight="20">
40+
android:text=""
41+
android:textAppearance="?android:attr/textAppearanceSmall"
42+
android:layout_height="wrap_content"
43+
android:paddingLeft="2dp"
44+
android:paddingRight="2dp"
45+
android:scrollbars="vertical"
46+
android:scrollbarStyle="outsideOverlay"
47+
android:scrollbarAlwaysDrawVerticalTrack="true"/>
3248

33-
<Button
34-
android:id="@+id/btnCopyLogcat"
35-
android:layout_width="match_parent"
36-
android:layout_height="match_parent"
37-
android:layout_alignParentBottom="true"
38-
android:text="Copy to sdcard" />
39-
</LinearLayout>
4049
</LinearLayout>
4150

4251

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="nativescript_blue">#3c5afd</color>
4+
</resources>

0 commit comments

Comments
 (0)