From a59d5fc9a48794bef3f2e45887cbfb8c4136f3f6 Mon Sep 17 00:00:00 2001 From: aswin7469 Date: Mon, 4 Aug 2025 18:38:27 +0530 Subject: [PATCH] nt-fwk: create stub for NtOnlineConfig * Required by nothing camera app * Part of Nt-framework on stock --- .../src/com/nothing/ext/INtOnlineConfig.java | 16 ++++++ .../nothing/onlineconfig/ConfigGrabber.java | 35 ++++++++++++ .../nothing/onlineconfig/ConfigObserver.java | 43 ++++++++++++++ .../onlineconfig/NtOnlineConfigImpl.java | 26 +++++++++ .../sdk/onlineconfig/ConfigObserver.java | 56 +++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 nt-fwk/src/com/nothing/ext/INtOnlineConfig.java create mode 100644 nt-fwk/src/com/nothing/onlineconfig/ConfigGrabber.java create mode 100644 nt-fwk/src/com/nothing/onlineconfig/ConfigObserver.java create mode 100644 nt-fwk/src/com/nothing/onlineconfig/NtOnlineConfigImpl.java create mode 100644 nt-fwk/src/com/nothing/sdk/onlineconfig/ConfigObserver.java diff --git a/nt-fwk/src/com/nothing/ext/INtOnlineConfig.java b/nt-fwk/src/com/nothing/ext/INtOnlineConfig.java new file mode 100644 index 0000000..dded177 --- /dev/null +++ b/nt-fwk/src/com/nothing/ext/INtOnlineConfig.java @@ -0,0 +1,16 @@ +package com.nothing.ext; + +import android.content.ContentResolver; +import android.database.ContentObserver; +import org.json.JSONArray; + +public interface INtOnlineConfig { + public static final INtOnlineConfig DEFAULT = new INtOnlineConfig() {}; + + default JSONArray grabConfig(ContentResolver resolver, String projectName) { + return null; + } + + default void registerContentObserver(ContentResolver resolver, String projectName, boolean notifyForDescendants, ContentObserver observer) { + } +} diff --git a/nt-fwk/src/com/nothing/onlineconfig/ConfigGrabber.java b/nt-fwk/src/com/nothing/onlineconfig/ConfigGrabber.java new file mode 100644 index 0000000..4af7c8c --- /dev/null +++ b/nt-fwk/src/com/nothing/onlineconfig/ConfigGrabber.java @@ -0,0 +1,35 @@ +package com.nothing.onlineconfig; + +import android.content.Context; +import android.util.Log; +import org.json.JSONArray; + +/** + * A stub for the com.nothing.onlineconfig.ConfigGrabber class. + * The original application uses reflection to instantiate this class, + * and the constructor was likely causing a crash. This stub provides a + * safe, non-functional implementation that will be found by the reflection + * code and will not crash. + */ +public class ConfigGrabber { + private static final String TAG = "ConfigGrabberStub"; + + // The original constructor likely took a Context and a String. + // We must match this signature for the reflection call to succeed. + public ConfigGrabber(Context context, String projectName) { + Log.d(TAG, "ConfigGrabber stub created for project: " + projectName); + // The original constructor would have been the source of the crash. + // We've replaced it with this safe, no-op implementation. + } + + /** + * Stubs the grabConfig method to return an empty JSONArray. + * This prevents any dependent code from processing a null or invalid config. + * + * @return An empty JSONArray. + */ + public JSONArray grabConfig() { + Log.d(TAG, "grabConfig() called on stub. Returning an empty JSONArray."); + return new JSONArray(); + } +} diff --git a/nt-fwk/src/com/nothing/onlineconfig/ConfigObserver.java b/nt-fwk/src/com/nothing/onlineconfig/ConfigObserver.java new file mode 100644 index 0000000..210c228 --- /dev/null +++ b/nt-fwk/src/com/nothing/onlineconfig/ConfigObserver.java @@ -0,0 +1,43 @@ +package com.nothing.onlineconfig; + +import android.content.Context; +import android.database.ContentObserver; +import android.os.Handler; +import android.util.Log; +import org.json.JSONArray; + +public class ConfigObserver extends ContentObserver { + private static final String TAG = "ConfigObserverStub"; + + public interface ConfigUpdater { + void updateConfig(JSONArray jSONArray); + } + + // A dependency on ConfigGrabber, which we now have a stub for. + private final ConfigGrabber mConfigGrabber; + private final ConfigUpdater mConfigUpdater; + + public ConfigObserver(Context context, Handler handler, ConfigUpdater configUpdater, String projectName) { + super(handler); + Log.d(TAG, "ConfigObserver stub created."); + this.mConfigGrabber = new ConfigGrabber(context, projectName); + this.mConfigUpdater = configUpdater; + } + + public void register() { + Log.d(TAG, "register() called on stub. No-op."); + } + + public void unregister() { + Log.d(TAG, "unregister() called on stub. No-op."); + } + + @Override + public void onChange(boolean selfChange) { + super.onChange(selfChange); + Log.d(TAG, "onChange() called on stub. Notifying updater with empty config."); + if (mConfigUpdater != null) { + mConfigUpdater.updateConfig(mConfigGrabber.grabConfig()); + } + } +} diff --git a/nt-fwk/src/com/nothing/onlineconfig/NtOnlineConfigImpl.java b/nt-fwk/src/com/nothing/onlineconfig/NtOnlineConfigImpl.java new file mode 100644 index 0000000..2a6d98a --- /dev/null +++ b/nt-fwk/src/com/nothing/onlineconfig/NtOnlineConfigImpl.java @@ -0,0 +1,26 @@ +package com.nothing.onlineconfig; + +import android.content.ContentResolver; +import android.database.ContentObserver; +import android.util.Log; +import com.nothing.ext.INtOnlineConfig; +import org.json.JSONArray; + +public class NtOnlineConfigImpl implements INtOnlineConfig { + private static final String TAG = "NtOnlineConfigImplStub"; + + public NtOnlineConfigImpl() { + Log.d(TAG, "NtOnlineConfigImpl stub created."); + } + + @Override + public JSONArray grabConfig(ContentResolver resolver, String projectName) { + Log.d(TAG, "grabConfig() called on stub. Returning an empty array."); + return new JSONArray(); + } + + @Override + public void registerContentObserver(ContentResolver resolver, String projectName, boolean notifyForDescendants, ContentObserver observer) { + Log.d(TAG, "registerContentObserver() called on stub. No-op."); + } +} diff --git a/nt-fwk/src/com/nothing/sdk/onlineconfig/ConfigObserver.java b/nt-fwk/src/com/nothing/sdk/onlineconfig/ConfigObserver.java new file mode 100644 index 0000000..df8c3f9 --- /dev/null +++ b/nt-fwk/src/com/nothing/sdk/onlineconfig/ConfigObserver.java @@ -0,0 +1,56 @@ +package com.nothing.sdk.onlineconfig; + +import android.content.Context; +import android.database.ContentObserver; +import android.os.Handler; +import android.util.Log; +import org.json.JSONArray; +import com.nothing.onlineconfig.NtOnlineConfigImpl; + +/** + * A stub for the ConfigObserver class, located in the com.nothing.sdk.onlineconfig package. + * This class is the direct cause of the crash, as indicated by the logcat. This stub + * provides a non-functional, safe implementation to prevent the app from crashing. + */ +public class ConfigObserver extends ContentObserver { + private static final String TAG = "ConfigObserverStub"; + + public interface ConfigUpdater { + void updateConfig(JSONArray jSONArray); + } + + // A simple stub for the ConfigGrabber dependency + private static class ConfigGrabberStub { + public ConfigGrabberStub(Context context, String projectName) {} + public JSONArray grabConfig() { return new JSONArray(); } + } + + private final ConfigGrabberStub mConfigGrabber; + private final ConfigUpdater mConfigUpdater; + + public ConfigObserver(Context context, Handler handler, ConfigUpdater configUpdater, String projectName) { + super(handler); + Log.d(TAG, "ConfigObserver stub created. This should prevent the crash."); + // We create a local stub for ConfigGrabber to avoid dependencies on other stubs. + this.mConfigGrabber = new ConfigGrabberStub(context, projectName); + this.mConfigUpdater = configUpdater; + // The original code here is likely the source of the crash. We are bypassing it. + } + + public void register() { + Log.d(TAG, "register() called on stub. No-op."); + } + + public void unregister() { + Log.d(TAG, "unregister() called on stub. No-op."); + } + + @Override + public void onChange(boolean selfChange) { + super.onChange(selfChange); + Log.d(TAG, "onChange() called on stub. Notifying updater with empty config."); + if (mConfigUpdater != null) { + mConfigUpdater.updateConfig(mConfigGrabber.grabConfig()); + } + } +}