Skip to content
Closed
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
61 changes: 61 additions & 0 deletions .github/workflows/pr171-fix-analyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PR171 fix analyzer errors
on:
push:
branches: [resolve/pr171-ci]
permissions:
contents: write
jobs:
fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: resolve/pr171-ohos
fetch-depth: 0
- name: Fix remaining semantic-port errors
shell: bash
run: |
set -eu
git config user.name "哥哥科技"
git config user.email "175325443+ucxn@users.noreply.github.com"
python3 - <<'PY'
from pathlib import Path

# 1) Lifecycle merge: one extra brace closed the State class early.
p = Path('lib/plugin/pl_player/view/view.dart')
s = p.read_text()
bad = ''' if (state != AppLifecycleState.paused && state != AppLifecycleState.detached) {\n plPlayerController.autoResumeInPipIfNeeded();\n }\n }\n if (!plPlayerController.continuePlayInBackground.value) {'''
good = ''' if (state != AppLifecycleState.paused && state != AppLifecycleState.detached) {\n plPlayerController.autoResumeInPipIfNeeded();\n }\n if (!plPlayerController.continuePlayInBackground.value) {'''
if bad not in s:
raise SystemExit('lifecycle brace pattern not found')
p.write_text(s.replace(bad, good, 1))

# 2) OHOS added a serialized setDataSource wrapper. Carry liveUid through
# both wrapper -> private implementation layers for playback statistics.
p = Path('lib/plugin/pl_player/controller.dart')
s = p.read_text()
call = ''' pgcType: pgcType,\n videoType: videoType,'''
if call not in s:
raise SystemExit('setDataSource wrapper call anchor not found')
s = s.replace(call, ''' pgcType: pgcType,\n liveUid: liveUid,\n videoType: videoType,''', 1)
private_sig = ''' int? seasonId,\n int? pgcType,\n VideoType? videoType,'''
if private_sig not in s:
raise SystemExit('private _setDataSource signature anchor not found')
s = s.replace(private_sig, ''' int? seasonId,\n int? pgcType,\n int? liveUid,\n VideoType? videoType,''', 1)
p.write_text(s)

# 3) This PR targets the OHOS fork. Keep the shared Windows probe API
# shape but do not import a win32 FFI implementation incompatible with
# the fork's pinned win32 version. Windows enhancement can be ported
# separately without blocking the playback-time feature.
Path('lib/utils/windows/network_info.dart').write_text('''final class WindowsNetworkInfo {\n const WindowsNetworkInfo({this.rssi, this.wifiMbps, this.wiredMbps});\n\n final int? rssi;\n final int? wifiMbps;\n final int? wiredMbps;\n}\n\nabstract final class WindowsNetworkInfoReader {\n static const _empty = WindowsNetworkInfo();\n\n static WindowsNetworkInfo read() => _empty;\n}\n''')
PY

if grep -R -n -E '^(<<<<<<<|=======|>>>>>>>)' lib android; then
echo 'Conflict markers remain' >&2
exit 1
fi
git diff --check
git add lib/plugin/pl_player/view/view.dart lib/plugin/pl_player/controller.dart lib/utils/windows/network_info.dart
git commit -m "fix: adapt playback insights to OHOS runtime"
git push origin HEAD:resolve/pr171-ohos
22 changes: 22 additions & 0 deletions .github/workflows/pr171-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: PR171 validate resolved OHOS tree
on:
push:
branches: [resolve/pr171-ci]
permissions:
contents: read
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: resolve/pr171-ohos
- uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: "3.41.9"
cache: true
- run: flutter pub get
env:
GIT_LFS_SKIP_SMUDGE: 1
- run: dart analyze --no-fatal-warnings
45 changes: 45 additions & 0 deletions android/app/src/main/java/com/example/piliplus/AndroidHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import android.graphics.drawable.Icon;
import android.media.session.PlaybackState;
import android.net.Uri;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.provider.MediaStore;
import android.provider.Settings;
Expand Down Expand Up @@ -64,6 +68,47 @@ public static int sdkInt() {
return Build.VERSION.SDK_INT;
}

@SuppressWarnings("deprecation")
public static int[] networkInfo() {
Context context = getContext();
ConnectivityManager connectivityManager = context.getSystemService(ConnectivityManager.class);
NetworkCapabilities capabilities = connectivityManager == null
? null
: connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
if (capabilities == null || !capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
return null;
}

int linkSpeed = -1;
int rssi = -127;
int signalLevel = -1;
WifiManager wifiManager = context.getSystemService(WifiManager.class);
if (wifiManager != null) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
linkSpeed = wifiInfo.getLinkSpeed();
rssi = wifiInfo.getRssi();
if (rssi > -127 && rssi <= 0) {
signalLevel = WifiManager.calculateSignalLevel(rssi, 5);
}
}
}

int flags = connectivityManager.isActiveNetworkMetered() ? 1 : 0;
if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL)) {
flags |= 2;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
&& !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED)) {
flags |= 4;
}
if (Build.VERSION.SDK_INT >= 36
&& !capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_BANDWIDTH_CONSTRAINED)) {
flags |= 8;
}
return new int[]{linkSpeed, rssi, signalLevel, flags};
}

public static void back() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
Expand Down
12 changes: 11 additions & 1 deletion lib/http/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import 'package:PiliPlus/http/constants.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/http/retry_interceptor.dart';
import 'package:PiliPlus/http/user.dart';
import 'package:PiliPlus/models/common/network_profile.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/accounts/account.dart';
import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
import 'package:PiliPlus/utils/connectivity_utils.dart';
import 'package:PiliPlus/utils/global_data.dart';
import 'package:PiliPlus/utils/login_utils.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
Expand Down Expand Up @@ -249,7 +251,15 @@ class Request {
return status != null && status >= 200 && status < 300;
};

if (Platform.isIOS) _watchConnectivity();
if (Platform.isIOS) {
_watchConnectivity();
} else {
ConnectivityUtils.changes.listen((change) {
if (change.reason == NetworkPolicyReason.network) {
_resetAdaptersForNetworkChange();
}
});
}
}

/*
Expand Down
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import 'package:PiliPlus/router/app_pages.dart';
import 'package:PiliPlus/services/account_service.dart';
import 'package:PiliPlus/services/download/download_service.dart';
import 'package:PiliPlus/services/logger.dart';
import 'package:PiliPlus/services/playback_stats_service.dart';
import 'package:PiliPlus/services/service_locator.dart';
import 'package:PiliPlus/utils/cache_manager.dart';
import 'package:PiliPlus/utils/calc_window_position.dart';
import 'package:PiliPlus/utils/connectivity_utils.dart';
import 'package:PiliPlus/utils/date_utils.dart';
import 'package:PiliPlus/utils/extension/core_palettes_ext.dart';
import 'package:PiliPlus/utils/extension/theme_ext.dart';
Expand Down Expand Up @@ -108,12 +110,14 @@ void main() async {
if (kDebugMode) debugPrint('GStorage init error: $e');
exit(0);
}
PlaybackStatsService.initializeAppLifecycle();
ScaledWidgetsFlutterBinding.instance.scaleFactor = Pref.uiScale;
await Future.wait([
_initDownPath(),
_initTmpPath(),
CacheManager.ensureInitialized(),
]);
await ConnectivityUtils.initialize();
Get
..lazyPut(AccountService.new)
..lazyPut(DownloadService.new);
Expand Down
42 changes: 42 additions & 0 deletions lib/models/common/network_profile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
enum NetworkTransport {
wifi('Wi-Fi'),
wired('有线网络'),
cellular('蜂窝网络'),
other('其他网络');

const NetworkTransport(this.label);
final String label;
}

enum NetworkPolicyReason { network, peak }

final class NetworkProfile {
const NetworkProfile({
required this.transport,
required this.useCellularPreferences,
this.rssi,
this.linkSpeedMbps,
this.signalLevel,
this.metered = false,
this.weakHint = false,
});

final NetworkTransport transport;
final bool useCellularPreferences;
final int? rssi;
final int? linkSpeedMbps;
final int? signalLevel;
final bool metered;
final bool weakHint;

String get preferenceLabel => useCellularPreferences ? '等效移网' : '等效宽带';

Object get identity => (transport, useCellularPreferences);
}

final class NetworkPolicyChange {
const NetworkPolicyChange(this.profile, this.reason);

final NetworkProfile profile;
final NetworkPolicyReason reason;
}
2 changes: 2 additions & 0 deletions lib/models/common/reply/reply_sort_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ enum ReplySortType {
final String label;
final String? text;
const ReplySortType(this.title, this.label, {this.text});

String get reply2Title => this == time ? '最早评论' : title;
}
Loading
Loading