Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 15 additions & 84 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,94 +1,25 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["DetectDeveloperMode_kotlinVersion"]

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["DetectDeveloperMode_" + name]
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["DetectDeveloperMode_" + name]).toInteger()
}

def supportsNamespace() {
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
def major = parsed[0].toInteger()
def minor = parsed[1].toInteger()

// Namespace support was added in 7.3.0
return (major == 7 && minor >= 3) || major >= 8
}
apply plugin: 'com.android.library'

android {
if (supportsNamespace()) {
namespace "com.detectdevelopermode"

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
}
compileSdkVersion safeExtGet('compileSdkVersion', 33)
buildToolsVersion safeExtGet('buildToolsVersion', "33.0.0")

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 23)
targetSdkVersion safeExtGet('targetSdkVersion', 33)
versionCode 1
versionName "1.0"
}
}

compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

}

buildTypes {
release {
minifyEnabled false
lintOptions {
warning 'InvalidPackage'
}
}

lintOptions {
disable "GradleCompatible"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
mavenCentral()
google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.facebook.react:react-native:+'
implementation 'com.scottyab:rootbeer-lib:0.0.9'
}

5 changes: 0 additions & 5 deletions android/gradle.properties

This file was deleted.

24 changes: 1 addition & 23 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.detectdevelopermode">

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

package="com.DetectDeveloperMode">
</manifest>
2 changes: 0 additions & 2 deletions android/src/main/AndroidManifestNew.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.DetectDeveloperMode;

import android.content.pm.ApplicationInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Debug;
import android.provider.Settings;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

public class DetectDeveloperModeModule extends ReactContextBaseJavaModule {

ReactApplicationContext reactContext;


public DetectDeveloperModeModule(ReactApplicationContext reactContext, boolean loadConstantsAsynchronously) {
super(reactContext);

this.reactContext = reactContext;

}

@Override
public String getName() {
return "DetectDeveloperMode";
}


@ReactMethod
public void isDevelopmentSettingsMode(Promise p) {
boolean isDevelopmentSettingsMode;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
isDevelopmentSettingsMode = Settings.System.getInt(this.reactContext.getContentResolver(), Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) != 1;
} else {
isDevelopmentSettingsMode = Settings.Global.getInt(this.reactContext.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1;
}
p.resolve(isDevelopmentSettingsMode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.DetectDeveloperMode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

public class DetectDeveloperModePackage implements ReactPackage {

private boolean mLoadConstantsAsynchronously;

public DetectDeveloperModePackage() {
this(false);
}

public DetectDeveloperModePackage(boolean loadConstantsAsynchronously) {
mLoadConstantsAsynchronously = loadConstantsAsynchronously;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new DetectDeveloperModeModule(reactContext, mLoadConstantsAsynchronously));
return modules;
}

// Deprecated RN 0.47
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(
ReactApplicationContext reactContext) {
return Collections.emptyList();
}

}

This file was deleted.

This file was deleted.

23 changes: 8 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { NativeModules, Platform } from "react-native";

const LINKING_ERROR =
`The package 'react-native-detect-developer-mode' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
"- You rebuilt the app after installing the package\n" +
"- You are not using Expo Go\n";
const { DetectDeveloperMode } = NativeModules;

const DetectDeveloperMode = NativeModules.DetectDeveloperMode;
if (DetectDeveloperMode == null) console.warn("DetectDeveloperMode is not available, check your native dependencies have linked correctly and ensure your app has been rebuilt");

if (!DetectDeveloperMode) {
throw new Error(LINKING_ERROR);
}

export function isDeveloperModeEnabled() {
if (!DetectDeveloperMode.isDeveloperModeEnabled) {
throw new Error(LINKING_ERROR);
export default {
isDevelopmentSettingsMode: () => {
// API only available on Android, return false for all other platforms.
if (Platform.OS !== "android") return Promise.resolve(false);
return DetectDeveloperMode.isDevelopmentSettingsMode();
}
return DetectDeveloperMode.isDeveloperModeEnabled();
}
};