-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/new architecture #33
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
Open
zeemyself
wants to merge
3
commits into
master
Choose a base branch
from
feature/new-architecture
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,66 @@ | ||
| def isNewArchitectureEnabled() { | ||
| return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" | ||
| } | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:3.1.3' | ||
| classpath 'com.android.tools.build:gradle:7.4.2' | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'com.android.library' | ||
|
|
||
| if (isNewArchitectureEnabled()) { | ||
| apply plugin: 'com.facebook.react' | ||
| } | ||
|
|
||
| android { | ||
| compileSdkVersion 27 | ||
| buildToolsVersion "28.0.3" | ||
| namespace "com.zeemyself.powermanager" | ||
| compileSdkVersion 34 | ||
| buildToolsVersion "34.0.0" | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion 16 | ||
| targetSdkVersion 22 | ||
| minSdkVersion 21 | ||
| targetSdkVersion 34 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
|
|
||
| buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() | ||
| } | ||
|
|
||
| sourceSets { | ||
| main { | ||
| if (isNewArchitectureEnabled()) { | ||
| java.srcDirs += ['src/newarch/java'] | ||
| } else { | ||
| java.srcDirs += ['src/oldarch/java'] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig true | ||
| } | ||
|
|
||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'com.facebook.react:react-native:+' | ||
| } | ||
|
|
||
| if (isNewArchitectureEnabled()) { | ||
| // RNGP handles dependencies under New Architecture | ||
| } else { | ||
| implementation 'com.facebook.react:react-native:+' | ||
| } | ||
| } |
74 changes: 0 additions & 74 deletions
74
android/src/main/java/com/zeemyself/powermanager/RNPowermanagerModule.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
android/src/main/java/com/zeemyself/powermanager/RNPowermanagerModuleImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.zeemyself.powermanager; | ||
|
|
||
| import android.content.ComponentName; | ||
| import android.content.Intent; | ||
| import android.content.pm.PackageManager; | ||
| import android.net.Uri; | ||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import java.util.Map; | ||
| import java.util.HashMap; | ||
|
|
||
| public class RNPowermanagerModuleImpl { | ||
| public static final String NAME = "RNPowermanager"; | ||
|
|
||
| private final ReactApplicationContext reactContext; | ||
|
|
||
| public RNPowermanagerModuleImpl(ReactApplicationContext reactContext) { | ||
| this.reactContext = reactContext; | ||
| } | ||
|
|
||
| private static final Intent[] POWERMANAGER_INTENTS = { | ||
| new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")), | ||
| new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")), | ||
| new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")), | ||
| new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")), | ||
| new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")), | ||
| new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")), | ||
| new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")), | ||
| new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).setData(Uri.parse("mobilemanager://function/entry/AutoStart")), | ||
| new Intent().setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")) | ||
| }; | ||
|
|
||
| public void startPowerManager() { | ||
| for (Intent intent : POWERMANAGER_INTENTS) { | ||
| if (reactContext.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) { | ||
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
| reactContext.startActivity(intent); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public Boolean isSupported() { | ||
| for (Intent intent : POWERMANAGER_INTENTS) { | ||
| if (reactContext.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public Map<String, Object> getConstants() { | ||
| final Map<String, Object> constants = new HashMap<>(); | ||
| constants.put("isSupported", isSupported()); | ||
| return constants; | ||
| } | ||
| } |
46 changes: 29 additions & 17 deletions
46
android/src/main/java/com/zeemyself/powermanager/RNPowermanagerPackage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,39 @@ | ||
| package com.zeemyself.powermanager; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import com.facebook.react.ReactPackage; | ||
| import com.facebook.react.TurboReactPackage; | ||
| import com.facebook.react.bridge.NativeModule; | ||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import com.facebook.react.uimanager.ViewManager; | ||
| import com.facebook.react.bridge.JavaScriptModule; | ||
| public class RNPowermanagerPackage implements ReactPackage { | ||
| @Override | ||
| public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
| return Arrays.<NativeModule>asList(new RNPowermanagerModule(reactContext)); | ||
| } | ||
| import com.facebook.react.module.model.ReactModuleInfo; | ||
| import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| // Deprecated from RN 0.47 | ||
| public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
| return Collections.emptyList(); | ||
| public class RNPowermanagerPackage extends TurboReactPackage { | ||
|
|
||
| @Override | ||
| public NativeModule getModule(String name, ReactApplicationContext reactContext) { | ||
| if (name.equals(RNPowermanagerModuleImpl.NAME)) { | ||
| return new RNPowermanagerModule(reactContext); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
| return Collections.emptyList(); | ||
| public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
| return () -> { | ||
| final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>(); | ||
| boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
| moduleInfos.put( | ||
| RNPowermanagerModuleImpl.NAME, | ||
| new ReactModuleInfo( | ||
| RNPowermanagerModuleImpl.NAME, | ||
| RNPowermanagerModuleImpl.NAME, | ||
| false, // canOverrideExistingModule | ||
| false, // needsEagerInit | ||
| false, // isCxxModule | ||
| isTurboModule // isTurboModule | ||
| )); | ||
| return moduleInfos; | ||
| }; | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
android/src/newarch/java/com/zeemyself/powermanager/RNPowermanagerModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.zeemyself.powermanager; | ||
|
|
||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import java.util.Map; | ||
|
|
||
| public class RNPowermanagerModule extends NativeRNPowermanagerSpec { | ||
|
|
||
| private final RNPowermanagerModuleImpl delegate; | ||
|
|
||
| public RNPowermanagerModule(ReactApplicationContext reactContext) { | ||
| super(reactContext); | ||
| this.delegate = new RNPowermanagerModuleImpl(reactContext); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RNPowermanagerModuleImpl.NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public void startPowerManager() { | ||
| delegate.startPowerManager(); | ||
| } | ||
|
|
||
| @Override | ||
| protected Map<String, Object> getTypedExportedConstants() { | ||
| return delegate.getConstants(); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
android/src/oldarch/java/com/zeemyself/powermanager/RNPowermanagerModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.zeemyself.powermanager; | ||
|
|
||
| import com.facebook.react.bridge.ReactApplicationContext; | ||
| import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
| import com.facebook.react.bridge.ReactMethod; | ||
| import androidx.annotation.Nullable; | ||
| import java.util.Map; | ||
|
|
||
| public class RNPowermanagerModule extends ReactContextBaseJavaModule { | ||
|
|
||
| private final RNPowermanagerModuleImpl delegate; | ||
|
|
||
| public RNPowermanagerModule(ReactApplicationContext reactContext) { | ||
| super(reactContext); | ||
| this.delegate = new RNPowermanagerModuleImpl(reactContext); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RNPowermanagerModuleImpl.NAME; | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void startPowerManager() { | ||
| delegate.startPowerManager(); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Map<String, Object> getConstants() { | ||
| return delegate.getConstants(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
|
|
||
| import { NativeModules, Platform } from 'react-native'; | ||
| import { Platform } from 'react-native'; | ||
| import RNPowermanager from './src/NativeRNPowermanager'; | ||
|
|
||
| const { RNPowermanager } = NativeModules; | ||
| // Cache constants for isSupported if RNPowermanager exists | ||
| const constants = RNPowermanager | ||
| ? (typeof RNPowermanager.getConstants === 'function' | ||
| ? RNPowermanager.getConstants() | ||
| : RNPowermanager) | ||
| : null; | ||
|
|
||
| export default PowerManager = { | ||
| startPowerManager: () => { | ||
| if(Platform.OS === 'android') { | ||
| return RNPowermanager.startPowerManager() | ||
| if (Platform.OS === 'android' && RNPowermanager) { | ||
| return RNPowermanager.startPowerManager(); | ||
| } | ||
| }, | ||
| isSupported: () => { | ||
| if(Platform.OS === 'android') { | ||
| return RNPowermanager.isSupported | ||
| if (Platform.OS === 'android' && constants) { | ||
| return constants.isSupported; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { TurboModule } from 'react-native'; | ||
| import { TurboModuleRegistry } from 'react-native'; | ||
|
|
||
| export interface Spec extends TurboModule { | ||
| startPowerManager(): void; | ||
| getConstants(): { | ||
| isSupported: boolean; | ||
| }; | ||
| } | ||
|
|
||
| export default TurboModuleRegistry.get<Spec>('RNPowermanager'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package still advertises support for
react-native >=0.71.0, but in RN 0.71/0.72ReactModuleInforequires thehasConstantsargument beforeisCxxModule; this six-argument constructor is only compatible with newer RN versions. Apps using the declared minimum will fail Android compilation when this package is included, so either add the missinghasConstantsvalue here or raise the peer dependency to the version where this constructor exists.Useful? React with 👍 / 👎.